-
-
Notifications
You must be signed in to change notification settings - Fork 81
/
markdown.cljs
35 lines (32 loc) · 1.22 KB
/
markdown.cljs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
(ns portal.ui.viewer.markdown
(:require [hickory.core :refer [parse-fragment as-hiccup]]
[hickory.utils :as utils]
[markdown.common :as common]
[markdown.core :refer [md->html]]
[portal.ui.inspector :as ins]
[portal.ui.viewer.hiccup :refer [inspect-hiccup]]))
(defn ^:no-doc parse-markdown [value]
(with-redefs
[common/escape-code identity
common/escaped-chars identity
utils/html-escape identity]
(->> (md->html value)
parse-fragment
(map as-hiccup)
(into [:div {:style {:max-width "1012px"
:margin "0 auto"}}]))))
(defn inspect-markdown [value]
;; I couldn't figure out a good way to disable html escaping, which
;; occurs in both markdown-clj and hickory, so I decided to manually
;; intercepts calls into utility methods and replace their
;; implementations. This is probably brittle, but I have little choice.
(with-redefs
[common/escape-code identity
common/escaped-chars identity
utils/html-escape identity]
[ins/inc-depth
[inspect-hiccup (parse-markdown value)]]))
(def viewer
{:predicate string?
:component inspect-markdown
:name :portal.viewer/markdown})