From c663b7040e822a08166c49438e0b064e1af5b1f9 Mon Sep 17 00:00:00 2001 From: Andrea Amantini Date: Thu, 15 Aug 2024 10:53:07 +0200 Subject: [PATCH] Introduce parse* to keep parsing ctx open --- src/nextjournal/markdown.cljc | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/nextjournal/markdown.cljc b/src/nextjournal/markdown.cljc index 8168667..b54da31 100644 --- a/src/nextjournal/markdown.cljc +++ b/src/nextjournal/markdown.cljc @@ -7,18 +7,25 @@ ;; TODO: remove fixme (shadow compile warnings) (defn tokenize [_] []) +(defn parse* + "Turns a markdown string into a nested clojure structure. + Allows to append (-> ctx (parse* text-1) (parse* text-2))" + ([markdown-text] (parse* u/empty-doc markdown-text)) + ([ctx markdown-text] + (-> ctx + (update :text-tokenizers (partial map u/normalize-tokenizer)) + (impl/parse markdown-text)))) + (defn parse "Turns a markdown string into a nested clojure structure." ([markdown-text] (parse u/empty-doc markdown-text)) ([ctx markdown-text] - (-> ctx - (update :text-tokenizers (partial map u/normalize-tokenizer)) - (impl/parse markdown-text) - (dissoc :label->footnote-ref - :nextjournal.markdown.parser.impl/id->index - :nextjournal.markdown.parser.impl/path - :text-tokenizers - :text->id+emoji-fn)))) + (dissoc (parse* ctx markdown-text) + :label->footnote-ref + :nextjournal.markdown.parser.impl/id->index + :nextjournal.markdown.parser.impl/path + :text-tokenizers + :text->id+emoji-fn))) (defn ->hiccup "Turns a markdown string into hiccup."