cripslock

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 4607be8cdb1cb7445fdf9c18e4515f7803e827a8
parent 0f7fa3aa37e38230c84e0b5f491b115a63962382
Author: Daniel Barlow <dan@telent.net>
Date:   Tue, 15 Jul 2025 23:41:19 +0100

parse links

Diffstat:
Mtextile.fnl | 20+++++++++++++++-----
1 file changed, 15 insertions(+), 5 deletions(-)

diff --git a/textile.fnl b/textile.fnl @@ -80,16 +80,25 @@ "*" (scan-tok "*" :strong) "@" (let [s (scan-tok "@" :code)] (fn [_ str] (s (fn [x] [x]) str))) + + "\"" (fn [f str] + (let [(title url unparsed) + (string.match str "^\"(.-)\":(%g+) +(.+)$")] + (values + (doto (f title) + (table.insert 1 [:a {:href url} ])) + unparsed))) + ;; this one must be last + "-" (scan-tok "-" :del) }) (local inline-token-pattern (.. "([" (accumulate [chrs "" c _ (pairs inline-tokens)] - (.. (string.sub c 1 1) chrs)) + (.. "%" (string.sub c 1 1) chrs)) "])")) - (fn inline-markup [str] (if (= str "") nil @@ -118,10 +127,11 @@ ;; nested the other way around (expect= (inline-markup "john _paul *george*_") ["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"]] + ) + ) {}