Skip to content

Commit a22f3ba

Browse files
authored
Accept parsed result in ->hiccup function (#43)
1 parent 72911c9 commit a22f3ba

File tree

4 files changed

+50
-44
lines changed

4 files changed

+50
-44
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Bump markdown-it to 14.1.0
99
* Render `:code` according to spec into `<pre>` and `<code>` block with language class (see [#39](https://github.com/nextjournal/markdown/issues/39))
1010
* No longer depend on `applied-science/js-interop`
11+
* Accept parsed result in `->hiccup` function
1112

1213
## 0.6.157
1314

resources/js/markdown.mjs

Lines changed: 39 additions & 40 deletions
Large diffs are not rendered by default.

src/nextjournal/markdown.cljc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,12 @@
4545

4646
(defn ->hiccup
4747
"Turns a markdown string into hiccup."
48-
([markdown-text] (->hiccup markdown.transform/default-hiccup-renderers markdown-text))
49-
([ctx markdown-text] (->> markdown-text parse (markdown.transform/->hiccup ctx))))
48+
([markdown] (->hiccup markdown.transform/default-hiccup-renderers markdown))
49+
([ctx markdown]
50+
(let [parsed (if (string? markdown)
51+
(parse markdown)
52+
markdown)]
53+
(markdown.transform/->hiccup ctx parsed))))
5054

5155
(comment
5256
(parse "# 🎱 Hello")

test/nextjournal/markdown_test.cljc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,10 @@ $$\\int_a^bf(t)dt$$
212212
[:li
213213
[:p
214214
"two"]]]]
215-
(md/->hiccup markdown-text)))))
215+
(md/->hiccup markdown-text))))
216+
(testing "-:hiccup function accepts parsed and string"
217+
(is (= [:div [:h1 {:id "hello"} "Hello"]] (md/->hiccup (md/parse "# Hello"))))
218+
(is (= [:div [:h1 {:id "hello"} "Hello"]] (md/->hiccup "# Hello")))))
216219

217220
(deftest strikethrough-test
218221
(testing "single tilde")
@@ -1076,7 +1079,6 @@ line
10761079
10771080
link</a>")))))))
10781081

1079-
10801082
;; Hello <a href=\"dude\">*Dude*</a>
10811083

10821084
(comment

0 commit comments

Comments
 (0)