Skip to content

Commit

Permalink
Fix ToC in presence of block formulas (#20)
Browse files Browse the repository at this point in the history
The formula plugin we're using didn't restore the parser level after pushing their tokens, this messed up our criterium for adding nodes into the table of contents.

The bug was fixed upstream in v1.0.0 with goessner/markdown-it-texmath#42.
  • Loading branch information
zampino authored Nov 28, 2023
1 parent 492efce commit 7617e5d
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 22 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
"markdown-it": "^12.2.0",
"markdown-it-block-image": "^0.0.3",
"markdown-it-footnote": "^3.0.3",
"markdown-it-texmath": "^0.9.1",
"markdown-it-texmath": "^1.0.0",
"markdown-it-toc-done-right": "^4.2.0",
"punycode": "2.1.1",
"react": "^18.2.0",
Expand Down
32 changes: 16 additions & 16 deletions resources/js/markdown.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/deps.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
"markdown-it" "^12.2.0"
"markdown-it-block-image" "^0.0.3"
"markdown-it-footnote" "^3.0.3"
"markdown-it-texmath" "^0.9.1"
"markdown-it-texmath" "^1.0.0"
"markdown-it-toc-done-right" "^4.2.0"
"punycode" "2.1.1"}}
1 change: 1 addition & 0 deletions src/nextjournal/markdown/parser.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,7 @@ end"
doc' (assign-node-id+emoji doc)
heading (-> doc' (get-in path) (assoc :path path))]
(cond-> doc'
;; We're only considering top-level headings (e.g. not those contained inside quotes or lists)
(zero? doc-level)
(-> (add-to-toc heading)
(set-title-when-missing heading)))))
Expand Down
14 changes: 14 additions & 0 deletions test/nextjournal/markdown_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -756,6 +756,20 @@ Par.
"Explain 2"]]]]
(md.transform/->hiccup parsed+sidenotes))))))

(deftest repro-19-test
(is (match? {:type :toc
:children [{:type :toc
:heading-level 1
:children [{:type :toc
:heading-level 2}]}]}
(:toc (md/parse "# Title
some par
$$p(z\\\\mid x) = \\\\frac{p(x\\\\mid z)p(z)}{p(x)}.$$\n\n
## SubTitle
")))))

(comment
(doseq [[n v] (ns-publics *ns*)] (ns-unmap *ns* n))
(clojure.test/run-tests)
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -601,10 +601,10 @@ markdown-it-footnote@^3.0.3:
resolved "https://registry.yarnpkg.com/markdown-it-footnote/-/markdown-it-footnote-3.0.3.tgz#e0e4c0d67390a4c5f0c75f73be605c7c190ca4d8"
integrity sha512-YZMSuCGVZAjzKMn+xqIco9d1cLGxbELHZ9do/TSYVzraooV8ypsppKNmUJ0fVH5ljkCInQAtFpm8Rb3eXSrt5w==

markdown-it-texmath@^0.9.1:
version "0.9.7"
resolved "https://registry.yarnpkg.com/markdown-it-texmath/-/markdown-it-texmath-0.9.7.tgz#4d1256def5f49ac09c48e4a79d715a1bba5025c9"
integrity sha512-2oZ7WO+xQCvQpfCwxUsCzDpz5jRjiY+FbSJSVz+66+Z9NoPR7ljzUNaOp1CDHYj0JWx+drQLxO0XUjuSsuqc0A==
markdown-it-texmath@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/markdown-it-texmath/-/markdown-it-texmath-1.0.0.tgz#65703b235d07a8f96bc58cbf9d478af57154e5f0"
integrity sha512-4hhkiX8/gus+6e53PLCUmUrsa6ZWGgJW2XCW6O0ASvZUiezIK900ZicinTDtG3kAO2kon7oUA/ReWmpW2FByxg==

markdown-it-toc-done-right@^4.2.0:
version "4.2.0"
Expand Down

0 comments on commit 7617e5d

Please sign in to comment.