diff --git a/CHANGELOG.md b/CHANGELOG.md index d31fc0b..2211a55 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ ## Unreleased -... +- Add option `:disable-footnotes true` to disable parsing footnotes [#67](https://github.com/nextjournal/markdown/issues/67) ## 0.7.222 diff --git a/src/js/markdown.js b/src/js/markdown.js index 0660b13..9299142 100644 --- a/src/js/markdown.js +++ b/src/js/markdown.js @@ -48,7 +48,9 @@ function MD(opts) { md.use(texmath, {delimiters: "dollars", ...opts}) md.use(blockImage) md.use(mdToc) - md.use(footnotes) + if (!opts.disable_footnotes) { + md.use(footnotes) + } md.use(todoListPlugin) return md; } diff --git a/src/nextjournal/markdown.cljc b/src/nextjournal/markdown.cljc index 5c3969b..b879e31 100644 --- a/src/nextjournal/markdown.cljc +++ b/src/nextjournal/markdown.cljc @@ -23,7 +23,8 @@ Accepted `opts`: - `:text-tokenizers`: customize parsing of text in leaf nodes (see https://nextjournal.github.io/markdown/notebooks/parsing_extensibility). - - `:disable-inline-formulas`: turn off parsing of $-delimited inline formulas." + - `:disable-inline-formulas`: turn off parsing of $-delimited inline formulas. + - `:disable-footnotes`: turn off parsing of footnotes." ([markdown-string] (parse {} markdown-string)) ([opts markdown-string] (-> (parse* {:opts opts} markdown-string) diff --git a/src/nextjournal/markdown/impl.clj b/src/nextjournal/markdown/impl.clj index e600553..00a08dd 100644 --- a/src/nextjournal/markdown/impl.clj +++ b/src/nextjournal/markdown/impl.clj @@ -46,14 +46,15 @@ (^Parser [ctx] (.. Parser builder - (extensions [(extensions/create ctx) - (AutolinkExtension/create) - (TaskListItemsExtension/create) - (TablesExtension/create) - (StrikethroughExtension/create) - (.. (FootnotesExtension/builder) - (inlineFootnotes true) - (build))]) + (extensions (cond-> [(extensions/create ctx) + (AutolinkExtension/create) + (TaskListItemsExtension/create) + (TablesExtension/create) + (StrikethroughExtension/create)] + (not (:disable-footnotes (:opts ctx))) + (conj (.. (FootnotesExtension/builder) + (inlineFootnotes true) + (build))))) build))) ;; helpers / ctx diff --git a/src/nextjournal/markdown/impl.cljs b/src/nextjournal/markdown/impl.cljs index 8c8a878..496096e 100644 --- a/src/nextjournal/markdown/impl.cljs +++ b/src/nextjournal/markdown/impl.cljs @@ -286,7 +286,8 @@ _this #should be a tag_, but this [_actually #foo shouldnt_](/bar/) is not." (assoc :doc (u/->zip ctx-in) :footnotes (u/->zip {:type :footnotes :content (or (:footnotes ctx-in) [])})) - (apply-tokens (md/tokenize #js {:disable_inline_formulas (:disable-inline-formulas (:opts ctx-in))} + (apply-tokens (md/tokenize #js {:disable_inline_formulas (:disable-inline-formulas (:opts ctx-in)) + :disable_footnotes (:disable-footnotes (:opts ctx-in))} markdown)))] (-> ctx-out (dissoc :doc) diff --git a/test/nextjournal/markdown_test.cljc b/test/nextjournal/markdown_test.cljc index 6c1475d..578e6c5 100644 --- a/test/nextjournal/markdown_test.cljc +++ b/test/nextjournal/markdown_test.cljc @@ -1114,6 +1114,25 @@ link"))))))) "**$1** $200") [:toc :content :footnotes :type])))) +(deftest disable-footnotes-test + (is (= {:toc {:type :toc}, + :footnotes [], + :content + [{:type :paragraph, + :content [{:type :text, :text "text ^[a-z] more"}]}], + :type :doc} + (md/parse {:disable-footnotes true} + "text ^[a-z] more"))) + (is (= {:toc {:type :toc}, + :footnotes [], + :content + [{:type :paragraph, + :content [{:type :text, :text "text ^[a-z] more"}]}], + :type :doc} + (select-keys (md/parse* {:opts {:disable-footnotes true}} + "text ^[a-z] more") + [:toc :content :footnotes :type])))) + (deftest disable-default-opts-test (is (nil? (-> (md/parse {:text->id+emoji-fn nil} "# 🎱 Hello 😀")