commit 99599adeb54817639d592c72d929d7db1765f4a3 parent 11d40133c39ce5fc163733c691027a011da06f96 Author: Daniel Barlow <dan@telent.net> Date: Thu, 17 Jul 2025 22:43:32 +0100 fix nesting bug in inline-markup Diffstat:
| M | textile.fnl | | | 30 | +++++++++++++++++++++++------- |
1 file changed, 23 insertions(+), 7 deletions(-)
diff --git a/textile.fnl b/textile.fnl @@ -107,12 +107,23 @@ nil (case (string.find str inline-token-pattern) (start end tok) - (let [(during after) ((. inline-tokens tok) inline-markup (string.sub str end))] - [ - (string.sub str 1 (- start 1)) - during - (inline-markup after) - ]) + (let [(during after) + ((. inline-tokens tok) inline-markup (string.sub str end)) + marked-after (or (inline-markup after) [])] + (if (> start 1) + (list-append + [ + (string.sub str 1 (- start 1)) + during + ] + marked-after + ) + (list-append + [ + during + ] + marked-after + ))) _ [str]))) (define-tests :inline-markup @@ -124,6 +135,9 @@ (expect= (inline-markup "foo *strong*") ["foo " [:strong "strong"]]) + (expect= (inline-markup "before *during* after") + ["before " [:strong "during"] " after"]) + ;; nested markup (expect= (inline-markup "foo *strong _em_*") ["foo " [:strong "strong " [:em "em"]]]) @@ -132,7 +146,9 @@ ["john " [:em "paul " [:strong "george"]]]) (expect= (inline-markup "see \"a link\":https://www.example.com for more") - ["see " [["a" {:href "https://www.example.com"}] "a link"] ["for more"]]) + ["see " [["a" {:href "https://www.example.com"}] "a link"] "for more"]) + + ) ;; a list item starts with one or more * or # in the left-hand column and