commit 96e356b8babb247a6d047e33504340115a00de77
parent 90c7b93461dab91cc9dab8bca4b8622c8fb4c6b5
Author: Daniel Barlow <dan@telent.net>
Date: Sun, 20 Jul 2025 22:17:48 +0100
textile: handle lone @ _ " etc
not every punctiuation character is necessarily an inline markup
introducer
Diffstat:
1 file changed, 20 insertions(+), 9 deletions(-)
diff --git a/textile.fnl b/textile.fnl
@@ -76,10 +76,13 @@
(fn scan-tok [endtok tag]
(fn [f str]
(let [(s e) (string.find str endtok 2 true)]
- (values
- (doto (f (string.sub str 2 (- s 1)))
- (table.insert 1 tag))
- (string.sub str (+ e 1))))))
+ (if s
+ (values
+ (doto (f (string.sub str 2 (- s 1)))
+ (table.insert 1 tag))
+ (string.sub str (+ e 1)))
+ (values str "")
+ ))))
(local inline-tokens {
"_" (scan-tok "_" :em)
@@ -90,10 +93,13 @@
"\"" (fn [f str]
(let [(title url unparsed)
(string.match str "^\"(.-)\":(%g+) +(.+)$")]
- (values
- (doto (f title)
- (table.insert 1 [:a {:href url} ]))
- unparsed)))
+ (if title
+ (values
+ (doto (f title)
+ (table.insert 1 [:a {:href url} ]))
+ unparsed)
+ (values str "")
+ )))
;; this one must be last
"-" (scan-tok "-" :del)
})
@@ -106,7 +112,7 @@
"])"))
(fn inline-markup [str]
- (if (= str "")
+ (if (or (not str) (= str ""))
nil
(case (string.find str inline-token-pattern)
(start end tok)
@@ -136,6 +142,11 @@
;; markup in code blocks is ignored
(expect= (inline-markup "foo @1+_2_+3@") ["foo " [:code "1+_2_+3"] ])
+ (expect= (inline-markup "foo@example.com") ["foo" "@example.com" ])
+
+ (expect= (inline-markup "say \"hello\" to my friend")
+ ["say " "\"hello\" to my friend"])
+
(expect= (inline-markup "foo *strong*") ["foo " [:strong "strong"]])
(expect= (inline-markup "before *during* after")