Skip to content

Commit

Permalink
Add auto-link extension
Browse files Browse the repository at this point in the history
  • Loading branch information
zampino committed Sep 17, 2024
1 parent f8c6848 commit 37aa2ee
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:deps {applied-science/js-interop {:mvn/version "0.3.3"}
org.clojure/data.json {:mvn/version "2.4.0"}
org.commonmark/commonmark {:mvn/version "0.23.0"}
org.commonmark/commonmark-ext-autolink {:mvn/version "0.23.0"}
org.commonmark/commonmark-ext-footnotes {:mvn/version "0.23.0"}
org.commonmark/commonmark-ext-task-list-items {:mvn/version "0.23.0"}
org.commonmark/commonmark-ext-gfm-tables {:mvn/version "0.23.0"}
Expand Down
3 changes: 3 additions & 0 deletions dev/old_vs_new.clj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
[clojure.test.check.clojure-test :refer [defspec]]))

(comment
(= (md/parse "https://github.com")
(md-old/parse "https://github.com"))

(:body (http/get "https://jaspervdj.be/lorem-markdownum/markdown.txt?fenced-code-blocks=on"))

(let [sample (:body (http/get "https://jaspervdj.be/lorem-markdownum/markdown.txt?num-blocks=1000&fenced-code-blocks=on"))]
Expand Down
8 changes: 5 additions & 3 deletions src/nextjournal/markdown/impl.clj
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@
[nextjournal.markdown.impl.types]
[nextjournal.markdown.impl.extensions :as extensions]
[nextjournal.markdown.utils :as u])
(:import (org.commonmark.ext.gfm.tables TableBlock TableBody TableRow TableHead TableCell TablesExtension)
(:import (org.commonmark.ext.autolink AutolinkExtension)
(org.commonmark.ext.footnotes FootnotesExtension FootnoteReference FootnoteDefinition InlineFootnote)
(org.commonmark.ext.gfm.strikethrough Strikethrough StrikethroughExtension)
(org.commonmark.ext.gfm.tables TableBlock TableBody TableRow TableHead TableCell TablesExtension)
(org.commonmark.ext.task.list.items TaskListItemsExtension TaskListItemMarker)
(org.commonmark.parser Parser)
(org.commonmark.ext.footnotes FootnotesExtension FootnoteReference FootnoteDefinition InlineFootnote)
(org.commonmark.node Node AbstractVisitor
Document
BlockQuote
Expand All @@ -30,6 +30,7 @@
SoftLineBreak
HardLineBreak
Image)
(org.commonmark.parser Parser)
(nextjournal.markdown.impl.types BlockFormula InlineFormula ToC)))

(set! *warn-on-reflection* true)
Expand All @@ -56,6 +57,7 @@
(.. Parser
builder
(extensions [(extensions/create)
(AutolinkExtension/create)
(TaskListItemsExtension/create)
(TablesExtension/create)
(StrikethroughExtension/create)
Expand Down
7 changes: 7 additions & 0 deletions test/nextjournal/markdown_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,13 @@ $$\\int_a^bf(t)dt$$
[link]:/path/to/something
")

(deftest autolinks
(is (match? {:type :doc
:content [{:type :paragraph
:content [{:type :link
:content [{:type :text, :text "https://clerk.vision"}]}]}]}
(md/parse "https://clerk.vision"))))

(defn parse-internal-links [text]
(md/parse* (update u/empty-doc :text-tokenizers conj u/internal-link-tokenizer)
text))
Expand Down

0 comments on commit 37aa2ee

Please sign in to comment.