Skip to content

Commit 86a9e27

Browse files
authored
Support HTML blocks and inline HTML (#37)
Fixes #7.
1 parent 59471a0 commit 86a9e27

File tree

9 files changed

+386
-299
lines changed

9 files changed

+386
-299
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@
22

33
## Unreleased
44

5-
* Hiccup JVM compatibiltiy for fragments (see [#34](https://github.com/nextjournal/markdown/issues/34))
5+
* Hiccup JVM compatibility for fragments (see [#34](https://github.com/nextjournal/markdown/issues/34))
6+
* Support HTML blocks and inline HTML (see [#7](https://github.com/nextjournal/markdown/issues/7))
67

78
## 0.6.157
89

9-
* Swap out GraalJS ([#28](https://github.com/nextjournal/markdown/issues/28)) in favour of [commonmark-java](https://github.com/markdown-it/markdown-it) on the JVM side.
10+
* Swap out GraalJS ([#28](https://github.com/nextjournal/markdown/issues/28)) in favour of [commonmark-java](https://github.com/commonmark/commonmark-java) on the JVM side.
1011
This makes the library compatible with Java 22 and yields an approximate speedup of 10x. The clojurescript implementation stays the same.
1112
* Comply with commonmark rendering of images by default (see [#18](https://github.com/nextjournal/markdown/issues/18)).
1213

bb.edn

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@
112112
(println "Building jar")
113113
(clojure (str "-T:build jar :version '\"" (read-version) "\"'")))}
114114

115+
install {:doc "Install jar locally"
116+
:task (do
117+
(println "Installing locally")
118+
(clojure (str "-T:build install :version '\"" (read-version) "\"'")))}
119+
115120
ci:publish {:doc "Publish task which will be run on CI"
116121
:depends [-current-tag -current-branch]
117122
:task (do

build.clj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@
3838
(b/jar {:class-dir class-dir
3939
:jar-file (jar-file version)}))
4040

41+
(defn install [{:keys [version] :as opts}]
42+
(jar opts)
43+
(b/install {:basis basis
44+
:lib lib
45+
:version (:version opts)
46+
:jar-file (jar-file version)
47+
:class-dir class-dir}))
48+
4149
(defn deploy [{:keys [version] :as opts}]
4250
(println "Deploying version" (jar-file version) "to Clojars.")
4351
(jar opts)

deps.edn

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
:test
4343
{:extra-paths ["test"]
4444
:jvm-opts ["-Dclojure.main.report=stderr"]
45-
:extra-deps {nubank/matcher-combinators {:mvn/version "3.8.3"}}
45+
:extra-deps {nubank/matcher-combinators {:mvn/version "3.9.1"}
46+
hiccup/hiccup {:mvn/version "2.0.0-RC5"}}
4647
:exec-fn test-runner/run}
4748

4849
:shadow

src/deps.cljs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{:npm-deps
22
{"katex" "^0.12.0"
3-
"markdown-it" "^12.2.0"
3+
"markdown-it" "^14.1.0"
44
"markdown-it-block-image" "^0.0.3"
55
"markdown-it-footnote" "^3.0.3"
66
"markdown-it-texmath" "^1.0.0"

src/nextjournal/markdown/impl.clj

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
;; # 🧩 Parsing
22
(ns nextjournal.markdown.impl
33
(:require [clojure.zip :as z]
4-
[nextjournal.markdown.impl.types :as t]
54
[nextjournal.markdown.impl.extensions :as extensions]
5+
[nextjournal.markdown.impl.types :as t]
66
[nextjournal.markdown.utils :as u])
77
(:import (org.commonmark.ext.autolink AutolinkExtension)
88
(org.commonmark.ext.footnotes FootnotesExtension FootnoteReference FootnoteDefinition InlineFootnote)
@@ -29,7 +29,9 @@
2929
ThematicBreak
3030
SoftLineBreak
3131
HardLineBreak
32-
Image)
32+
HtmlInline
33+
Image
34+
HtmlBlock)
3335
(org.commonmark.parser Parser)))
3436

3537
(set! *warn-on-reflection* true)
@@ -102,7 +104,17 @@
102104
(defmethod close-node Heading [ctx ^Heading _node]
103105
(u/handle-close-heading ctx))
104106

105-
(defmethod open-node BulletList [ctx ^ListBlock node]
107+
(defmethod open-node HtmlInline [ctx ^HtmlInline node]
108+
(u/update-current-loc ctx (fn [loc] (u/zopen-node loc {:type :html-inline
109+
:content [{:type :text
110+
:text (.getLiteral node)}]}))))
111+
112+
(defmethod open-node HtmlBlock [ctx ^HtmlBlock node]
113+
(u/update-current-loc ctx (fn [loc] (u/zopen-node loc {:type :html-block
114+
:content [{:type :text
115+
:text (.getLiteral node)}]}))))
116+
117+
(defmethod open-node BulletList [ctx ^ListBlock _node]
106118
(u/update-current-loc ctx (fn [loc] (u/zopen-node loc {:type :bullet-list :content [] #_#_:tight? (.isTight node)}))))
107119

108120
(defmethod open-node OrderedList [ctx _node]

src/nextjournal/markdown/impl.cljs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -244,9 +244,13 @@ _this #should be a tag_, but this [_actually #foo shouldnt_](/bar/) is not."
244244
(defmethod apply-token "link_close" [doc _token] (close-node doc))
245245
(defmethod apply-token "code_inline" [doc {text :content}] (-> doc (open-node :monospace) (push-node (text-node text)) close-node))
246246

247-
;; html (ignored)
248-
(defmethod apply-token "html_inline" [doc _] doc)
249-
(defmethod apply-token "html_block" [doc _] doc)
247+
;; html
248+
(defmethod apply-token "html_inline" [doc token]
249+
(-> doc (u/update-current-loc z/append-child {:type :html-inline :content [(text-node (j/get token :content))]})))
250+
251+
(defmethod apply-token "html_block" [doc token]
252+
(-> doc (u/update-current-loc z/append-child {:type :html-block :content [(text-node (j/get token :content))]})))
253+
250254
;; endregion
251255

252256
;; region data builder api

0 commit comments

Comments
 (0)