From 1363ca13f794e68202f4c46e06219310debc7243 Mon Sep 17 00:00:00 2001 From: Tienson Qin Date: Mon, 30 May 2022 19:33:05 +0800 Subject: [PATCH] Add allowed tags --- src/main/frontend/extensions/html_parser.cljs | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/src/main/frontend/extensions/html_parser.cljs b/src/main/frontend/extensions/html_parser.cljs index a0700c1be..b22b3847b 100644 --- a/src/main/frontend/extensions/html_parser.cljs +++ b/src/main/frontend/extensions/html_parser.cljs @@ -20,6 +20,20 @@ (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 [format hiccup opts] (let [transform-fn (fn [hiccup opts] @@ -77,7 +91,10 @@ (if (string? pattern) pattern (apply str (reverse pattern))))))) wrapper (fn [tag content] (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 (and (= tag :p) (:in-table? opts)) @@ -239,7 +256,6 @@ (when-not (string/blank? html) (let [hiccup (hickory/as-hiccup (hickory/parse html)) decoded-hiccup (html-decode-hiccup hiccup)] - (def hiccup hiccup) (hiccup->doc format decoded-hiccup)))) (comment