Skip to content

Commit

Permalink
Introduce parse* to keep parsing ctx open
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Aug 15, 2024
1 parent 6097e09 commit c663b70
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/nextjournal/markdown.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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."
Expand Down

0 comments on commit c663b70

Please sign in to comment.