fix(editor): use denied tags in html to md conversion

pull/5792/head
Andelf 2022-06-22 14:42:18 +08:00 committed by Tienson Qin
parent f6ead67b23
commit 494c136bbd
1 changed files with 4 additions and 19 deletions

View File

@ -17,22 +17,10 @@
(defn- export-hiccup
[hiccup]
(util/format "#+BEGIN_EXPORT hiccup\n%s\n#+END_EXPORT"
(str (hiccup-without-style hiccup))))
(def allowed-tags
#{:address, :article, :aside, :footer, :header,
:h1, :h2, :h3, :h4, :h5, :h6, :hgroup,
:main, :nav, :section,
:blockquote, :dd, :div, :dl, :dt, :figcaption, :figure,
:hr, :li, :ol, :p, :pre, :ul,
:a, :abbr, :b, :bdi, :bdo, :br, :cite, :code, :data, :dfn,
:em, :i, :kbd, :mark, :q,
:rb, :rp, :rt, :rtc, :ruby,
:s, :samp, :small, :span, :strong, :sub, :sup, :time, :u, :var, :wbr,
:caption, :col, :colgroup, :table, :tbody, :td, :tfoot, :th,
:thead, :tr
:body :html})
(def denied-tags
#{:script :base :head :link :meta :style :title :comment :xml :svg :frame :frameset :embed :object :canvas :applet})
(defn ^:large-vars/cleanup-todo hiccup->doc-inner
[format hiccup opts]
@ -91,10 +79,7 @@
(if (string? pattern) pattern (apply str (reverse pattern)))))))
wrapper (fn [tag content]
(let [content (cond
(not (contains? allowed-tags tag))
nil
(contains? #{:comment :head :style :xml} tag)
(contains? denied-tags tag)
nil
(and (= tag :p) (:in-table? opts))
@ -233,7 +218,7 @@
(for [x hiccup]
(single-hiccup-transform x))
(single-hiccup-transform hiccup))]
(apply str result)))
(string/replace (apply str result) #"\n\n+" "\n\n")))
(defn hiccup->doc
[format hiccup]