Search code examples
clojurereagenthiccup

How to prevent HTML escaping in Clojure Reagent (Hiccup like)


I am using ClojureScript Reagent. Which provides hiccup-like HTML generation.

I have a String with HTML:

(def code "<b>hello world</b>")

When passed to Hiccup it will be escaped and I get no bold text on my page:

[:div code]

How to pass code to my HTML output so it will be integrated there without being escaped?


Solution

  • Reagent

    Use the dangerouslysetInnerHTML native React call

    [:div {:dangerouslySetInnerHTML {:__html code}}])
    

    Also see:

    (real) Hiccup

    You need to use the raw-string function from hiccup.utils:

    [:div (raw-string code)]