|
1 | 1 | ;; # 🧩 Parsing
|
2 | 2 | (ns nextjournal.markdown.impl
|
3 | 3 | (:require ["/js/markdown" :as md]
|
4 |
| - [applied-science.js-interop :as j] |
5 | 4 | [clojure.zip :as z]
|
6 | 5 | [nextjournal.markdown.utils :as u]))
|
7 | 6 |
|
|
123 | 122 |
|
124 | 123 | (defn footnote-label [{:as _ctx ::keys [footnote-offset]} token]
|
125 | 124 | ;; TODO: consider initial offset in case we're parsing multiple inputs
|
126 |
| - (or (j/get-in token [:meta :label]) |
| 125 | + (or (.. token -meta -label) |
127 | 126 | ;; inline labels won't have a label
|
128 |
| - (str "inline-note-" (+ footnote-offset (j/get-in token [:meta :id]))))) |
| 127 | + (str "inline-note-" (+ footnote-offset (.. token -meta -id))))) |
129 | 128 |
|
130 | 129 | ;; footnotes
|
131 | 130 | (defmethod apply-token "footnote_ref" [{:as ctx ::keys [label->footnote-ref]} token]
|
132 | 131 | (let [label (footnote-label ctx token)
|
133 | 132 | footnote-ref (or (get label->footnote-ref label)
|
134 |
| - {:type :footnote-ref :inline? (not (j/get-in token [:meta :label])) |
| 133 | + {:type :footnote-ref :inline? (not (.. token -meta -label)) |
135 | 134 | :ref (count label->footnote-ref) ;; was (+ (count footnotes) (j/get-in token [:meta :id])) ???
|
136 | 135 | :label label})]
|
137 | 136 | (-> ctx
|
|
144 | 143 | (-> ctx
|
145 | 144 | (u/update-current-loc (fn [loc]
|
146 | 145 | (u/zopen-node loc {:type :footnote
|
147 |
| - :inline? (not (j/get-in token [:meta :label])) |
| 146 | + :inline? (not (.. token -meta -label)) |
148 | 147 | :label label}))))))
|
149 | 148 |
|
150 | 149 | ;; inline footnotes^[like this one]
|
@@ -252,24 +251,26 @@ _this #should be a tag_, but this [_actually #foo shouldnt_](/bar/) is not."
|
252 | 251 |
|
253 | 252 | ;; html
|
254 | 253 | (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))]}))) |
| 254 | + (-> doc (u/update-current-loc z/append-child {:type :html-inline :content [(text-node (.-content token))]}))) |
256 | 255 |
|
257 | 256 | (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))]}))) |
| 257 | + (-> doc (u/update-current-loc z/append-child {:type :html-block :content [(text-node (.-content token))]}))) |
259 | 258 |
|
260 | 259 | ;; html
|
261 | 260 | (defmethod apply-token "html_inline" [doc token]
|
262 |
| - (-> doc (u/update-current-loc z/append-child {:type :html-inline :content [(text-node (j/get token :content))]}))) |
| 261 | + (-> doc (u/update-current-loc z/append-child {:type :html-inline :content [(text-node (.-content token))]}))) |
263 | 262 |
|
264 | 263 | (defmethod apply-token "html_block" [doc token]
|
265 |
| - (-> doc (u/update-current-loc z/append-child {:type :html-block :content [(text-node (j/get token :content))]}))) |
| 264 | + (-> doc (u/update-current-loc z/append-child {:type :html-block :content [(text-node (.-content token))]}))) |
266 | 265 |
|
267 | 266 | ;; endregion
|
268 | 267 |
|
269 | 268 | ;; region data builder api
|
270 | 269 | (defn pairs->kmap [pairs] (into {} (map (juxt (comp keyword first) second)) pairs))
|
271 | 270 | (defn apply-tokens [doc tokens]
|
272 |
| - (let [mapify-attrs-xf (map (fn [x] (j/update! x :attrs pairs->kmap)))] |
| 271 | + (let [mapify-attrs-xf (map (fn [x] |
| 272 | + (set! x -attrs (pairs->kmap (.-attrs x))) |
| 273 | + x))] |
273 | 274 | (reduce (mapify-attrs-xf apply-token) doc tokens)))
|
274 | 275 |
|
275 | 276 | (defn parse
|
|
0 commit comments