Add allowed tags

pull/5420/head
Tienson Qin 2022-05-30 19:33:05 +08:00
parent e147c88f08
commit 1363ca13f7
1 changed files with 18 additions and 2 deletions

View File

@ -20,6 +20,20 @@
(str (hiccup-without-style hiccup)))) (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})
(defn ^:large-vars/cleanup-todo hiccup->doc-inner (defn ^:large-vars/cleanup-todo hiccup->doc-inner
[format hiccup opts] [format hiccup opts]
(let [transform-fn (fn [hiccup opts] (let [transform-fn (fn [hiccup opts]
@ -77,7 +91,10 @@
(if (string? pattern) pattern (apply str (reverse pattern))))))) (if (string? pattern) pattern (apply str (reverse pattern)))))))
wrapper (fn [tag content] wrapper (fn [tag content]
(let [content (cond (let [content (cond
(contains? #{:comment :head :w :style :xml :o:p} tag) (not (contains? allowed-tags tag))
nil
(contains? #{:comment :head :style :xml} tag)
nil nil
(and (= tag :p) (:in-table? opts)) (and (= tag :p) (:in-table? opts))
@ -239,7 +256,6 @@
(when-not (string/blank? html) (when-not (string/blank? html)
(let [hiccup (hickory/as-hiccup (hickory/parse html)) (let [hiccup (hickory/as-hiccup (hickory/parse html))
decoded-hiccup (html-decode-hiccup hiccup)] decoded-hiccup (html-decode-hiccup hiccup)]
(def hiccup hiccup)
(hiccup->doc format decoded-hiccup)))) (hiccup->doc format decoded-hiccup))))
(comment (comment