commit 28712970d0ebdd8c88c9318a5891230a84b64569 parent 12105544e26f3f24c10bed2618d1b1bf7cc45779 Author: Daniel Barlow <dan@telent.net> Date: Tue, 15 Jul 2025 23:16:16 +0100 parse blocks into tag and body Diffstat:
| M | textile.fnl | | | 28 | ++++++++++++++++++++++++++++ |
1 file changed, 28 insertions(+), 0 deletions(-)
diff --git a/textile.fnl b/textile.fnl @@ -17,5 +17,33 @@ (expect= (# paras) 4) (expect= (. paras 2) "this is\nalso a paragraph\n")))) +(local block-tags + (doto (collect [_ v (ipairs [ + :h1 + :h2 + :h3 + :h4 + :h5 + :h6 + :p + :pre + :fn + ])] + (values v v)) + (tset :bq "blockquote"))) + + +(fn tag-and-body [block] + (case (string.find block "^([%a%d]-)%. *") + (start end tag) (values (. block-tags tag) (string.sub block (+ end 1))) + _ (values :p block))) + +(define-tests :tag-and-body + (let [(t b) (tag-and-body "p. my paragraph")] + (expect= [t b] [:p "my paragraph"])) + (let [(t b) (tag-and-body "h1. header")] + (expect= [t b] [:h1 "header"])) + (let [(t b) (tag-and-body "bq. blockquoted")] + (expect= [t b] [:blockquote "blockquoted"]))) {}