Skip to content

Commit cfd3d4b

Browse files
authored
Upgrade commonmark-java and markdown-it (#38)
* Bump commonmark-java to 0.24.0 * Bump markdown-it to 14.1.0
1 parent 86a9e27 commit cfd3d4b

File tree

5 files changed

+93
-71
lines changed

5 files changed

+93
-71
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
* Hiccup JVM compatibility for fragments (see [#34](https://github.com/nextjournal/markdown/issues/34))
66
* Support HTML blocks and inline HTML (see [#7](https://github.com/nextjournal/markdown/issues/7))
7+
* Bump commonmark to 0.24.0
8+
* Bump markdown-it to 14.1.0
79

810
## 0.6.157
911

deps.edn

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{:paths ["src" "resources"]
22
:deps {applied-science/js-interop {:mvn/version "0.3.3"}
3-
org.commonmark/commonmark {:mvn/version "0.23.0"}
4-
org.commonmark/commonmark-ext-autolink {:mvn/version "0.23.0"}
5-
org.commonmark/commonmark-ext-footnotes {:mvn/version "0.23.0"}
6-
org.commonmark/commonmark-ext-task-list-items {:mvn/version "0.23.0"}
7-
org.commonmark/commonmark-ext-gfm-tables {:mvn/version "0.23.0"}
8-
org.commonmark/commonmark-ext-gfm-strikethrough {:mvn/version "0.23.0"}}
3+
org.commonmark/commonmark {:mvn/version "0.24.0"}
4+
org.commonmark/commonmark-ext-autolink {:mvn/version "0.24.0"}
5+
org.commonmark/commonmark-ext-footnotes {:mvn/version "0.24.0"}
6+
org.commonmark/commonmark-ext-task-list-items {:mvn/version "0.24.0"}
7+
org.commonmark/commonmark-ext-gfm-tables {:mvn/version "0.24.0"}
8+
org.commonmark/commonmark-ext-gfm-strikethrough {:mvn/version "0.24.0"}}
99

1010
:aliases
1111
{:nextjournal/clerk

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
"framer-motion": "^6.2.8",
2121
"katex": "^0.12.0",
2222
"lezer-clojure": "1.0.0-rc.0",
23-
"markdown-it": "^12.2.0",
23+
"markdown-it": "^14.1.0",
2424
"markdown-it-block-image": "^0.0.3",
2525
"markdown-it-footnote": "^3.0.3",
2626
"markdown-it-texmath": "^1.0.0",

src/nextjournal/markdown/impl.cljs

Lines changed: 52 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,13 @@
11
;; # 🧩 Parsing
22
(ns nextjournal.markdown.impl
33
(:require ["/js/markdown" :as md]
4-
["markdown-it/lib/token" :as Token]
54
[applied-science.js-interop :as j]
65
[clojure.zip :as z]
76
[nextjournal.markdown.utils :as u]))
87

9-
(extend-type Token
10-
ILookup
11-
(-lookup
12-
([this key] (j/get this key))
13-
([this key not-found]
14-
(js/console.log :ilookup/not-found this key not-found)
15-
(j/get this key not-found))))
16-
17-
(defn hlevel [{:as _token hn :tag}] (when (string? hn) (some-> (re-matches #"h([\d])" hn) second js/parseInt)))
8+
(defn hlevel [^js token]
9+
(let [hn (.-tag token)]
10+
(when (string? hn) (some-> (re-matches #"h([\d])" hn) second js/parseInt))))
1811

1912
;; leaf nodes
2013
;; TODO: use from utils
@@ -62,7 +55,7 @@
6255

6356
;; region token handlers
6457
(declare apply-tokens)
65-
(defmulti apply-token (fn [_doc token] (:type token)))
58+
(defmulti apply-token (fn [_doc ^js token] (.-type token)))
6659
(defmethod apply-token :default [doc token]
6760
(prn :apply-token/unknown-type {:token token})
6861
doc)
@@ -74,23 +67,30 @@
7467

7568
;; for building the TOC we just care about headings at document top level (not e.g. nested under lists) ⬆
7669

77-
(defmethod apply-token "paragraph_open" [doc {:as _token :keys [hidden]}]
70+
(defmethod apply-token "paragraph_open" [doc ^js token]
7871
;; no trace of tight vs loose on list nodes
7972
;; markdown-it passes this info directly to paragraphs via this `hidden` key
80-
(open-node doc (if hidden :plain :paragraph)))
73+
(open-node doc (if (.-hidden token) :plain :paragraph)))
8174

8275
(defmethod apply-token "paragraph_close" [doc _token] (close-node doc))
8376

84-
(defmethod apply-token "bullet_list_open" [doc {{:as attrs :keys [has-todos]} :attrs}] (open-node doc (if has-todos :todo-list :bullet-list) attrs))
77+
(defmethod apply-token "bullet_list_open" [doc ^js token]
78+
(let [attrs (.-attrs token)
79+
has-todos (:has-todos attrs)]
80+
(open-node doc (if has-todos :todo-list :bullet-list) attrs)))
81+
8582
(defmethod apply-token "bullet_list_close" [doc _token] (close-node doc))
8683

87-
(defmethod apply-token "ordered_list_open" [doc {:keys [attrs]}] (open-node doc :numbered-list attrs))
84+
(defmethod apply-token "ordered_list_open" [doc ^js token] (open-node doc :numbered-list (.-attrs token)))
8885
(defmethod apply-token "ordered_list_close" [doc _token] (close-node doc))
8986

90-
(defmethod apply-token "list_item_open" [doc {{:as attrs :keys [todo]} :attrs}] (open-node doc (if todo :todo-item :list-item) attrs))
87+
(defmethod apply-token "list_item_open" [doc ^js token]
88+
(let [attrs (.-attrs token)
89+
todo (:todo attrs)]
90+
(open-node doc (if todo :todo-item :list-item) attrs)))
9191
(defmethod apply-token "list_item_close" [doc _token] (close-node doc))
9292

93-
(defmethod apply-token "math_block" [doc {text :content}] (push-node doc (block-formula text)))
93+
(defmethod apply-token "math_block" [doc ^js token] (push-node doc (block-formula (.-content token))))
9494
(defmethod apply-token "math_block_end" [doc _token] doc)
9595

9696
(defmethod apply-token "hr" [doc _token] (push-node doc {:type :ruler}))
@@ -106,17 +106,20 @@
106106
(fn [loc]
107107
(-> loc (z/edit dissoc :content) z/up)))))
108108

109-
(defmethod apply-token "code_block" [doc {:as _token c :content}]
110-
(-> doc
111-
(open-node :code)
112-
(push-node (text-node c))
113-
close-node))
114-
115-
(defmethod apply-token "fence" [doc {:as _token i :info c :content}]
116-
(-> doc
117-
(open-node :code {} (assoc (u/parse-fence-info i) :info i))
118-
(push-node (text-node c))
119-
close-node))
109+
(defmethod apply-token "code_block" [doc ^js token]
110+
(let [c (.-content token)]
111+
(-> doc
112+
(open-node :code)
113+
(push-node (text-node c))
114+
close-node)))
115+
116+
(defmethod apply-token "fence" [doc ^js token]
117+
(let [c (.-content token)
118+
i (.-info token)]
119+
(-> doc
120+
(open-node :code {} (assoc (u/parse-fence-info i) :info i))
121+
(push-node (text-node c))
122+
close-node)))
120123

121124
(defn footnote-label [{:as _ctx ::keys [footnote-offset]} token]
122125
;; TODO: consider initial offset in case we're parsing multiple inputs
@@ -148,7 +151,7 @@
148151
(defmethod apply-token "footnote_close" [ctx _token]
149152
(-> ctx (u/update-current-loc z/up)))
150153

151-
(defmethod apply-token "footnote_block_open" [ctx token]
154+
(defmethod apply-token "footnote_block_open" [ctx _token]
152155
;; store footnotes at a top level `:footnote` key
153156
(assoc ctx ::root :footnotes))
154157

@@ -183,11 +186,11 @@
183186
(defmethod apply-token "thead_close" [doc _token] (close-node doc))
184187
(defmethod apply-token "tr_open" [doc _token] (open-node doc :table-row))
185188
(defmethod apply-token "tr_close" [doc _token] (close-node doc))
186-
(defmethod apply-token "th_open" [doc token] (open-node doc :table-header (:attrs token)))
189+
(defmethod apply-token "th_open" [doc ^js token] (open-node doc :table-header (.-attrs token)))
187190
(defmethod apply-token "th_close" [doc _token] (close-node doc))
188191
(defmethod apply-token "tbody_open" [doc _token] (open-node doc :table-body))
189192
(defmethod apply-token "tbody_close" [doc _token] (close-node doc))
190-
(defmethod apply-token "td_open" [doc token] (open-node doc :table-data (:attrs token)))
193+
(defmethod apply-token "td_open" [doc ^js token] (open-node doc :table-data (.-attrs token)))
191194
(defmethod apply-token "td_close" [doc _token] (close-node doc))
192195

193196
(comment
@@ -211,8 +214,8 @@
211214
_this #should be a tag_, but this [_actually #foo shouldnt_](/bar/) is not."
212215
(parse (update empty-doc :text-tokenizers conj (u/normalize-tokenizer u/hashtag-tokenizer)))))
213216

214-
(defmethod apply-token "text" [ctx {:keys [content]}]
215-
(u/handle-text-token ctx content))
217+
(defmethod apply-token "text" [ctx ^js token]
218+
(u/handle-text-token ctx (.-content token)))
216219

217220
(comment
218221
(def mustache (u/normalize-tokenizer {:regex #"\{\{([^\{]+)\}\}" :handler (fn [m] {:type :eval :text (m 1)})}))
@@ -221,17 +224,20 @@ _this #should be a tag_, but this [_actually #foo shouldnt_](/bar/) is not."
221224
"foo [[bar]] dang #hashy taggy [[what]] #dangy foo [[great]] and {{eval}} me"))
222225

223226
;; inlines
224-
(defmethod apply-token "inline" [doc {:as _token ts :children}] (apply-tokens doc ts))
225-
(defmethod apply-token "math_inline" [doc {text :content}] (push-node doc (formula text)))
226-
(defmethod apply-token "math_inline_double" [doc {text :content}] (push-node doc (formula text)))
227+
(defmethod apply-token "inline" [doc ^js token] (apply-tokens doc (.-children token)))
228+
(defmethod apply-token "math_inline" [doc ^js token] (push-node doc (formula (.-content token))))
229+
(defmethod apply-token "math_inline_double" [doc ^js token] (push-node doc (formula (.-content token))))
227230

228231
;; https://spec.commonmark.org/0.30/#softbreak
229232
(defmethod apply-token "softbreak" [doc _token] (push-node doc {:type :softbreak}))
230233
;; https://spec.commonmark.org/0.30/#hard-line-break
231234
(defmethod apply-token "hardbreak" [doc _token] (push-node doc {:type :hardbreak}))
232235

233236
;; images
234-
(defmethod apply-token "image" [doc {:keys [attrs children]}] (-> doc (open-node :image attrs) (apply-tokens children) close-node))
237+
(defmethod apply-token "image" [doc ^js token]
238+
(let [attrs (.-attrs token)
239+
children (.-children token)]
240+
(-> doc (open-node :image attrs) (apply-tokens children) close-node)))
235241

236242
;; marks
237243
(defmethod apply-token "em_open" [doc _token] (open-node doc :em))
@@ -240,9 +246,16 @@ _this #should be a tag_, but this [_actually #foo shouldnt_](/bar/) is not."
240246
(defmethod apply-token "strong_close" [doc _token] (close-node doc))
241247
(defmethod apply-token "s_open" [doc _token] (open-node doc :strikethrough))
242248
(defmethod apply-token "s_close" [doc _token] (close-node doc))
243-
(defmethod apply-token "link_open" [doc token] (open-node doc :link (:attrs token)))
249+
(defmethod apply-token "link_open" [doc ^js token] (open-node doc :link (.-attrs token)))
244250
(defmethod apply-token "link_close" [doc _token] (close-node doc))
245-
(defmethod apply-token "code_inline" [doc {text :content}] (-> doc (open-node :monospace) (push-node (text-node text)) close-node))
251+
(defmethod apply-token "code_inline" [doc ^js token] (-> doc (open-node :monospace) (push-node (text-node (.-content token))) close-node))
252+
253+
;; html
254+
(defmethod apply-token "html_inline" [doc token]
255+
(-> doc (u/update-current-loc z/append-child {:type :html-inline :content [(text-node (j/get token :content))]})))
256+
257+
(defmethod apply-token "html_block" [doc token]
258+
(-> doc (u/update-current-loc z/append-child {:type :html-block :content [(text-node (j/get token :content))]})))
246259

247260
;; html
248261
(defmethod apply-token "html_inline" [doc token]

yarn.lock

Lines changed: 32 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -449,10 +449,10 @@ emoji-regex@^10.0.0:
449449
resolved "https://registry.npmjs.org/emoji-regex/-/emoji-regex-10.1.0.tgz"
450450
integrity sha512-xAEnNCT3w2Tg6MA7ly6QqYJvEoY1tm9iIjJ3yMKK9JPlWuRHAMoe5iETwQnx3M9TVbFMfsrBgWKR+IsmswwNjg==
451451

452-
entities@~2.1.0:
453-
version "2.1.0"
454-
resolved "https://registry.npmjs.org/entities/-/entities-2.1.0.tgz"
455-
integrity sha512-hCx1oky9PFrJ611mf0ifBLBRW8lUUVRlFolb5gWRfIELabBlbp9xZvrqZLZAs+NxFnbfQoeGd8wDkygjg7U85w==
452+
entities@^4.4.0:
453+
version "4.5.0"
454+
resolved "https://registry.yarnpkg.com/entities/-/entities-4.5.0.tgz#5d268ea5e7113ec74c4d033b79ea5a35a488fb48"
455+
integrity sha512-V0hjH4dGPh9Ao5p0MoRY6BVqtwCjhz6vI5LT8AJ55H+4g9/4vbHx1I54fS0XuclLhDHArPQCiMjDxjaL8fPxhw==
456456

457457
esbuild@^0.12.28:
458458
version "0.12.29"
@@ -577,12 +577,12 @@ [email protected]:
577577
dependencies:
578578
"@lezer/lr" "^1.0.0"
579579

580-
linkify-it@^3.0.1:
581-
version "3.0.3"
582-
resolved "https://registry.npmjs.org/linkify-it/-/linkify-it-3.0.3.tgz"
583-
integrity sha512-ynTsyrFSdE5oZ/O9GEf00kPngmOfVwazR5GKDq6EYfhlpFug3J2zybX56a2PRRpc9P+FuSoGNAwjlbDs9jJBPQ==
580+
linkify-it@^5.0.0:
581+
version "5.0.0"
582+
resolved "https://registry.yarnpkg.com/linkify-it/-/linkify-it-5.0.0.tgz#9ef238bfa6dc70bd8e7f9572b52d369af569b421"
583+
integrity sha512-5aHCbzQRADcdP+ATqnDuhhJ/MRIqDkZX5pyjFHRRysS8vZ5AbqGEoFIb6pYHPZ+L/OC2Lc+xT8uHVVR5CAK/wQ==
584584
dependencies:
585-
uc.micro "^1.0.1"
585+
uc.micro "^2.0.0"
586586

587587
loose-envify@^1.1.0:
588588
version "1.4.0"
@@ -611,16 +611,18 @@ markdown-it-toc-done-right@^4.2.0:
611611
resolved "https://registry.npmjs.org/markdown-it-toc-done-right/-/markdown-it-toc-done-right-4.2.0.tgz"
612612
integrity sha512-UB/IbzjWazwTlNAX0pvWNlJS8NKsOQ4syrXZQ/C72j+jirrsjVRT627lCaylrKJFBQWfRsPmIVQie8x38DEhAQ==
613613

614-
markdown-it@^12.2.0:
615-
version "12.3.2"
616-
resolved "https://registry.npmjs.org/markdown-it/-/markdown-it-12.3.2.tgz"
617-
integrity sha512-TchMembfxfNVpHkbtriWltGWc+m3xszaRD0CZup7GFFhzIgQqxIfn3eGj1yZpfuflzPvfkt611B2Q/Bsk1YnGg==
614+
615+
markdown-it@^14.1.0:
616+
version "14.1.0"
617+
resolved "https://registry.yarnpkg.com/markdown-it/-/markdown-it-14.1.0.tgz#3c3c5992883c633db4714ccb4d7b5935d98b7d45"
618+
integrity sha512-a54IwgWPaeBCAAsv13YgmALOF1elABB08FxO9i+r4VFk5Vl4pKokRPeX8u5TCgSsPi6ec1otfLjdOpVcgbpshg==
618619
dependencies:
619620
argparse "^2.0.1"
620-
entities "~2.1.0"
621-
linkify-it "^3.0.1"
622-
mdurl "^1.0.1"
623-
uc.micro "^1.0.5"
621+
entities "^4.4.0"
622+
linkify-it "^5.0.0"
623+
mdurl "^2.0.0"
624+
punycode.js "^2.3.1"
625+
uc.micro "^2.1.0"
624626

625627
md5.js@^1.3.4:
626628
version "1.3.5"
@@ -631,10 +633,10 @@ md5.js@^1.3.4:
631633
inherits "^2.0.1"
632634
safe-buffer "^5.1.2"
633635

634-
mdurl@^1.0.1:
635-
version "1.0.1"
636-
resolved "https://registry.npmjs.org/mdurl/-/mdurl-1.0.1.tgz"
637-
integrity sha1-/oWy7HWlkDfyrf7BAP1sYBdhFS4=
636+
mdurl@^2.0.0:
637+
version "2.0.0"
638+
resolved "https://registry.yarnpkg.com/mdurl/-/mdurl-2.0.0.tgz#80676ec0433025dd3e17ee983d0fe8de5a2237e0"
639+
integrity sha512-Lf+9+2r+Tdp5wXDXC4PcIBjTDtq4UKjCPMQhKIuzpJNW0b96kVqSwW0bT7FhRSfmAiFYgP+SCRvdrDozfh0U5w==
638640

639641
miller-rabin@^4.0.0:
640642
version "4.0.1"
@@ -757,6 +759,11 @@ public-encrypt@^4.0.0:
757759
randombytes "^2.0.1"
758760
safe-buffer "^5.1.2"
759761

762+
punycode.js@^2.3.1:
763+
version "2.3.1"
764+
resolved "https://registry.yarnpkg.com/punycode.js/-/punycode.js-2.3.1.tgz#6b53e56ad75588234e79f4affa90972c7dd8cdb7"
765+
integrity sha512-uxFIHU0YlHYhDQtV4R9J6a52SLx28BCjT+4ieh7IGbgwVJWO+km431c4yRlREUAsAmt/uMjQUyQHNEPf0M39CA==
766+
760767
761768
version "1.3.2"
762769
resolved "https://registry.npmjs.org/punycode/-/punycode-1.3.2.tgz"
@@ -979,10 +986,10 @@ [email protected]:
979986
resolved "https://registry.npmjs.org/tty-browserify/-/tty-browserify-0.0.0.tgz"
980987
integrity sha512-JVa5ijo+j/sOoHGjw0sxw734b1LhBkQ3bvUGNdxnVXDCX81Yx7TFgnZygxrIIWn23hbfTaMYLwRmAxFyDuFmIw==
981988

982-
uc.micro@^1.0.1, uc.micro@^1.0.5:
983-
version "1.0.6"
984-
resolved "https://registry.npmjs.org/uc.micro/-/uc.micro-1.0.6.tgz"
985-
integrity sha512-8Y75pvTYkLJW2hWQHXxoqRgV7qb9B+9vFEtidML+7koHUFapnVJAZ6cKs+Qjz5Aw3aZWHMC6u0wJE3At+nSGwA==
989+
uc.micro@^2.0.0, uc.micro@^2.1.0:
990+
version "2.1.0"
991+
resolved "https://registry.yarnpkg.com/uc.micro/-/uc.micro-2.1.0.tgz#f8d3f7d0ec4c3dea35a7e3c8efa4cb8b45c9e7ee"
992+
integrity sha512-ARDJmphmdvUk6Glw7y9DQ2bFkKBHwQHLi2lsaH6PPmz/Ka9sFOBsBluozhDltWmnv9u/cF6Rt87znRTPV+yp/A==
986993

987994
url@^0.11.0:
988995
version "0.11.0"

0 commit comments

Comments
 (0)