Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion src/js/markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/nextjournal/markdown.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
17 changes: 9 additions & 8 deletions src/nextjournal/markdown/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/nextjournal/markdown/impl.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
19 changes: 19 additions & 0 deletions test/nextjournal/markdown_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -1114,6 +1114,25 @@ link</a>")))))))
"**$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 😀")
Expand Down
Loading