Skip to content

Commit 40ac7ac

Browse files
authored
Add option to disable footnotes (#67) (#68)
1 parent f37dfba commit 40ac7ac

6 files changed

Lines changed: 36 additions & 12 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
## Unreleased
66

7-
...
7+
- Add option `:disable-footnotes true` to disable parsing footnotes [#67](https://github.com/nextjournal/markdown/issues/67)
88

99
## 0.7.222
1010

src/js/markdown.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,9 @@ function MD(opts) {
4848
md.use(texmath, {delimiters: "dollars", ...opts})
4949
md.use(blockImage)
5050
md.use(mdToc)
51-
md.use(footnotes)
51+
if (!opts.disable_footnotes) {
52+
md.use(footnotes)
53+
}
5254
md.use(todoListPlugin)
5355
return md;
5456
}

src/nextjournal/markdown.cljc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@
2323
2424
Accepted `opts`:
2525
- `:text-tokenizers`: customize parsing of text in leaf nodes (see https://nextjournal.github.io/markdown/notebooks/parsing_extensibility).
26-
- `:disable-inline-formulas`: turn off parsing of $-delimited inline formulas."
26+
- `:disable-inline-formulas`: turn off parsing of $-delimited inline formulas.
27+
- `:disable-footnotes`: turn off parsing of footnotes."
2728
([markdown-string] (parse {} markdown-string))
2829
([opts markdown-string]
2930
(-> (parse* {:opts opts} markdown-string)

src/nextjournal/markdown/impl.clj

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,14 +46,15 @@
4646
(^Parser [ctx]
4747
(.. Parser
4848
builder
49-
(extensions [(extensions/create ctx)
50-
(AutolinkExtension/create)
51-
(TaskListItemsExtension/create)
52-
(TablesExtension/create)
53-
(StrikethroughExtension/create)
54-
(.. (FootnotesExtension/builder)
55-
(inlineFootnotes true)
56-
(build))])
49+
(extensions (cond-> [(extensions/create ctx)
50+
(AutolinkExtension/create)
51+
(TaskListItemsExtension/create)
52+
(TablesExtension/create)
53+
(StrikethroughExtension/create)]
54+
(not (:disable-footnotes (:opts ctx)))
55+
(conj (.. (FootnotesExtension/builder)
56+
(inlineFootnotes true)
57+
(build)))))
5758
build)))
5859

5960
;; helpers / ctx

src/nextjournal/markdown/impl.cljs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,8 @@ _this #should be a tag_, but this [_actually #foo shouldnt_](/bar/) is not."
286286
(assoc :doc (u/->zip ctx-in)
287287
:footnotes (u/->zip {:type :footnotes
288288
:content (or (:footnotes ctx-in) [])}))
289-
(apply-tokens (md/tokenize #js {:disable_inline_formulas (:disable-inline-formulas (:opts ctx-in))}
289+
(apply-tokens (md/tokenize #js {:disable_inline_formulas (:disable-inline-formulas (:opts ctx-in))
290+
:disable_footnotes (:disable-footnotes (:opts ctx-in))}
290291
markdown)))]
291292
(-> ctx-out
292293
(dissoc :doc)

test/nextjournal/markdown_test.cljc

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1114,6 +1114,25 @@ link</a>")))))))
11141114
"**$1** $200")
11151115
[:toc :content :footnotes :type]))))
11161116

1117+
(deftest disable-footnotes-test
1118+
(is (= {:toc {:type :toc},
1119+
:footnotes [],
1120+
:content
1121+
[{:type :paragraph,
1122+
:content [{:type :text, :text "text ^[a-z] more"}]}],
1123+
:type :doc}
1124+
(md/parse {:disable-footnotes true}
1125+
"text ^[a-z] more")))
1126+
(is (= {:toc {:type :toc},
1127+
:footnotes [],
1128+
:content
1129+
[{:type :paragraph,
1130+
:content [{:type :text, :text "text ^[a-z] more"}]}],
1131+
:type :doc}
1132+
(select-keys (md/parse* {:opts {:disable-footnotes true}}
1133+
"text ^[a-z] more")
1134+
[:toc :content :footnotes :type]))))
1135+
11171136
(deftest disable-default-opts-test
11181137
(is (nil? (-> (md/parse {:text->id+emoji-fn nil}
11191138
"# 🎱 Hello 😀")

0 commit comments

Comments
 (0)