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 @@ -2,7 +2,7 @@

## Unreleased

...
* Make `katex` dependency optional by inlining copy of [markdown-it-texmath](https://github.com/goessner/markdown-it-texmath) (see [#15](https://github.com/nextjournal/markdown/issues/15))

## 0.7.186

Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ A cross-platform clojure library for [Markdown](https://en.wikipedia.org/wiki/Ma
## Features

* _Focus on data_: parsing yields an AST ([à la Pandoc](https://nextjournal.github.io/markdown/notebooks/pandoc)) of nested data representing a structured document.
* _Cross Platform_: using [commonmark-java](https://github.com/commonmark/commonmark-java) on the JVM and [markdown-it](https://github.com/markdown-it/markdown-it) for clojurescript
* _Cross Platform_: using [commonmark-java](https://github.com/commonmark/commonmark-java) on the JVM and [markdown-it](https://github.com/markdown-it/markdown-it) for ClojureScript.
* _Configurable [Hiccup](https://github.com/weavejester/hiccup) conversion_.

## Try
Expand Down
5 changes: 3 additions & 2 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
:aliases
{:nextjournal/clerk
{:extra-paths ["notebooks" "dev"]
:extra-deps {io.github.nextjournal/clerk {:mvn/version "0.17.1102"
:extra-deps {io.github.nextjournal/clerk {:git/sha "39b73a0acf0b29ff8fef70ff462f170c21026a3f"
;; :mvn/version "0.17.1102"
:exclusions [io.github.nextjournal/markdown]}}
:jvm-opts ["-Dclojure.main.report=stderr"
#_"-Dclerk.resource_manifest={\"/js/viewer.js\" \"js/viewer.js\"}"] ;;
Expand All @@ -28,7 +29,7 @@
org.babashka/http-client {:mvn/version "0.3.11"}
org.clojure/data.json {:mvn/version "2.4.0"}
org.clojure/test.check {:mvn/version "1.1.1"}
io.github.nextjournal/clerk {:git/sha "f4c5488e36c8df11fe352889544e7deb9af73cb7"
io.github.nextjournal/clerk {:git/sha "39b73a0acf0b29ff8fef70ff462f170c21026a3f"
:exclusions [io.github.nextjournal/markdown]}
nubank/matcher-combinators {:mvn/version "3.8.3"}
hiccup/hiccup {:mvn/version "2.0.0-RC5"}}}
Expand Down
25 changes: 16 additions & 9 deletions dev/nextjournal/markdown/render.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
syntaxHighlighting]]
["@codemirror/state" :refer [EditorState]]
["@codemirror/view" :refer [EditorView keymap]]
["katex" :as katex]
["react" :as react]
[clojure.string :as str]
[nextjournal.clerk.render :as render]
Expand Down Expand Up @@ -76,33 +75,41 @@
(react/isValidElement result) result
:else [render/inspect result]))]]))

(def renderers
(defn renderers [katex]
(assoc md.transform/default-hiccup-renderers
:code (fn [_ctx node] [clojure-editor {:doc (md.transform/->text node)}])
:todo-item (fn [ctx {:as node :keys [attrs]}]
(md.transform/into-markup [:li [:input {:type "checkbox" :default-checked (:checked attrs)}]] ctx node))
:formula (fn [_ctx node]
[:span {:dangerouslySetInnerHTML {:__html (.renderToString katex (md.transform/->text node))}}])
[:span {:dangerouslySetInnerHTML (r/unsafe-html (.renderToString katex (md.transform/->text node)))}])
:block-formula (fn [_ctx node]
[:div {:dangerouslySetInnerHTML {:__html (.renderToString katex (md.transform/->text node) #js {:displayMode true})}}])))
[:div {:dangerouslySetInnerHTML (r/unsafe-html (.renderToString katex (md.transform/->text node) #js {:displayMode true}))}])))

(defn inspect-expanded [x]
(r/with-let [expanded-at (r/atom {:hover-path [] :prompt-multi-expand? false})]
(render/inspect-presented {:!expanded-at expanded-at}
(v/present x))))

(defn try-markdown [init-text]
(let [text->state (fn [text]


(defn try-markdown* [{:keys [init-text katex]}]
(let [text->state (fn [katex text]
(let [parsed (md/parse text)]
{:parsed parsed
:hiccup (nextjournal.markdown.transform/->hiccup renderers parsed)}))
!state (hooks/use-state (text->state init-text))]
:hiccup (nextjournal.markdown.transform/->hiccup (renderers katex) parsed)}))
!state (hooks/use-state (text->state katex init-text))]
[:div.grid.grid-cols-2.m-10
[:div.m-2.p-2.text-xl.border-2.overflow-y-scroll.bg-slate-100 {:style {:height "20rem"}}
[editor {:doc init-text :on-change #(reset! !state (text->state %)) :lang :markdown}]]
[editor {:doc init-text :on-change #(reset! !state (text->state katex %)) :lang :markdown}]]
[:div.m-2.p-2.font-medium.overflow-y-scroll {:style {:height "20rem"}}
[inspect-expanded (:parsed @!state)]]
[:div.m-2.p-2.overflow-x-scroll
[inspect-expanded (:hiccup @!state)]]
[:div.m-2.p-2.bg-slate-50.viewer-markdown
[v/html (:hiccup @!state)]]]))

(defn try-markdown [init-text]
(let [katex (hooks/use-d3-require "katex@0.16.4")]
(when katex
[try-markdown* {:init-text init-text
:katex katex}])))
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"d3-require": "^1.2.4",
"emoji-regex": "^10.0.0",
"framer-motion": "^6.2.8",
"katex": "^0.12.0",
"lezer-clojure": "1.0.0-rc.0",
"markdown-it": "^14.1.0",
"markdown-it-block-image": "^0.0.3",
Expand Down
3 changes: 1 addition & 2 deletions src/deps.cljs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
{:npm-deps
{"katex" "^0.12.0"
"markdown-it" "^14.1.0"
{"markdown-it" "^14.1.0"
"markdown-it-block-image" "^0.0.3"
"markdown-it-footnote" "^3.0.3"
"markdown-it-texmath" "^1.0.0"
Expand Down
Loading
Loading