|
2 | 2 | (:require ["marked" :refer [marked]]
|
3 | 3 | [clojure.string :as str]
|
4 | 4 | [portal.colors :as c]
|
| 5 | + [portal.ui.html :as h] |
5 | 6 | [portal.ui.icons :as icons]
|
6 | 7 | [portal.ui.inspector :as ins]
|
7 | 8 | [portal.ui.lazy :as l]
|
|
26 | 27 | (defn- ->text [^js token]
|
27 | 28 | (unescape (.-text token)))
|
28 | 29 |
|
29 |
| -(defn- ->style [string] |
30 |
| - (persistent! |
31 |
| - (reduce |
32 |
| - (fn [style rule] |
33 |
| - (let [[k v] (str/split rule #":")] |
34 |
| - (assoc! style (keyword (str/trim k)) (str/trim v)))) |
35 |
| - (transient {}) |
36 |
| - (str/split string #";")))) |
37 |
| - |
38 |
| -(defn- dom->hiccup [^js el] |
39 |
| - (case (.-nodeType el) |
40 |
| - 3 (.-wholeText el) |
41 |
| - 1 (let [attrs (.-attributes el)] |
42 |
| - (into |
43 |
| - [(keyword (str/lower-case (.-tagName el))) |
44 |
| - (persistent! |
45 |
| - (reduce |
46 |
| - (fn [attrs ^js attr] |
47 |
| - (let [k (keyword (.-name attr))] |
48 |
| - (assoc! attrs k |
49 |
| - (case k |
50 |
| - :style (->style (.-value attr)) |
51 |
| - (.-value attr))))) |
52 |
| - (transient {}) |
53 |
| - attrs))] |
54 |
| - (map dom->hiccup) |
55 |
| - (.-childNodes el))))) |
56 |
| - |
57 |
| -(defn- parse-dom [string] |
58 |
| - (-> (js/DOMParser.) |
59 |
| - (.parseFromString string "text/html") |
60 |
| - (.getElementsByTagName "body") |
61 |
| - (aget 0) |
62 |
| - (.-childNodes))) |
63 |
| - |
64 |
| -(defn- parse-html [html] |
65 |
| - (into [:<>] (map dom->hiccup) (parse-dom html))) |
66 |
| - |
67 | 30 | (defn- absolute-link? [href]
|
68 | 31 | (or (str/starts-with? href "http")
|
69 | 32 | (str/starts-with? href "https")))
|
|
182 | 145 | (fn [out ^js token]
|
183 | 146 | (case (.-type token)
|
184 | 147 | "escape" (conj out (->text token))
|
185 |
| - "html" (conj out (parse-html (.-text token))) |
| 148 | + "html" (conj out (h/parse-html (.-text token))) |
186 | 149 | "link" (conj out (->link token))
|
187 | 150 | "image" (conj out (->image token))
|
188 | 151 | "strong" (conj out (->strong token))
|
|
208 | 171 | "table" (conj out (->table token))
|
209 | 172 | "blockquote" (conj out (->blockquote token))
|
210 | 173 | "list" (conj out (->list token))
|
211 |
| - "html" (conj out (parse-html (->text token))) |
| 174 | + "html" (conj out (h/parse-html (->text token))) |
212 | 175 | "paragraph" (conj out (->paragraph token))
|
213 | 176 | "text" (if-let [tokens (.-tokens token)]
|
214 | 177 | (->inline out tokens)
|
|
0 commit comments