Skip to content

Commit

Permalink
Support strikethrough syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Aug 16, 2024
1 parent 8eb07b9 commit f6f16b8
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 2 deletions.
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
com.github.commonmark/commonmark-java {:mvn/version "faea2a2a61cfa1b1f26a4e914532b651b3602e34"}
com.github.commonmark.commonmark-java/commonmark-ext-task-list-items {:mvn/version "faea2a2a61cfa1b1f26a4e914532b651b3602e34"}
com.github.commonmark.commonmark-java/commonmark-ext-gfm-tables {:mvn/version "faea2a2a61cfa1b1f26a4e914532b651b3602e34"}
com.github.commonmark.commonmark-java/commonmark-ext-gfm-strikethrough {:mvn/version "faea2a2a61cfa1b1f26a4e914532b651b3602e34"}

;; jitpack bisect

Expand Down
9 changes: 7 additions & 2 deletions src/nextjournal/markdown/parser/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
[nextjournal.markdown.parser.impl.types]
[nextjournal.markdown.parser.impl.formulas :as formulas]
[nextjournal.markdown.parser.impl.utils :as u])
(:import (org.commonmark.parser Parser)
(:import (org.commonmark.ext.gfm.tables TableBlock TableBody TableRow TableHead TableCell TablesExtension)
(org.commonmark.ext.gfm.strikethrough Strikethrough StrikethroughExtension)
(org.commonmark.ext.task.list.items TaskListItemsExtension TaskListItemMarker)
(org.commonmark.ext.gfm.tables TableBlock TableBody TableRow TableHead TableCell TablesExtension)
(org.commonmark.parser Parser)
#_(org.commonmark.ext.footnotes FootnotesExtension FootnoteReference FootnoteDefinition InlineFootnote)
(org.commonmark.node Node AbstractVisitor
Document
Expand Down Expand Up @@ -57,6 +58,7 @@
(extensions [(formulas/extension)
(TaskListItemsExtension/create)
(TablesExtension/create)
(StrikethroughExtension/create)
#_(.. (FootnotesExtension/builder)
(inlineFootnotes true)
(build))])
Expand Down Expand Up @@ -144,6 +146,9 @@
:content [{:type :text
:text (.getLiteral node)}]}) z/down z/rightmost))))

(defmethod open-node Strikethrough [ctx _node]
(update-current ctx (fn [loc] (-> loc (z/append-child {:type :strikethrough :content []}) z/down z/rightmost))))

(defmethod open-node Link [ctx ^Link node]
(update-current ctx (fn [loc]
(-> loc (z/append-child {:type :link
Expand Down
9 changes: 9 additions & 0 deletions test/nextjournal/markdown_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,15 @@ $$\\int_a^bf(t)dt$$
"two"]]]]
(md/->hiccup markdown-text))))

(deftest strikethrough-test
(testing "single tilde")
;; Here markdown-it follows Pandoc and uses single ~ for 'sub' (enabled by default https://github.com/markdown-it/markdown-it/tree/master?tab=readme-ov-file#syntax-extensions).
;; It differs from GFM spec https://github.github.com/gfm/#strikethrough-extension- which allows signle tilde syntax
(testing "double tilde"
(is (= {:type :paragraph, :content [{:type :text, :text "some "} {:type :strikethrough, :content [{:type :text, :text "not ok"}]} {:type :text, :text " text"}]}
(-> (md/parse "some ~~not ok~~ text")
:content first)))))

(deftest tables-test
(is (= {:type :doc
:content [{:type :table
Expand Down

0 comments on commit f6f16b8

Please sign in to comment.