Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 825
Witek Avatar asked Sep 21 '16 17:09

Witek


1 Answers

Reagent

Use the dangerouslysetInnerHTML native React call

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

Also see:

  • Issue #14

(real) Hiccup

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

[:div (raw-string code)]
like image 112
Madara's Ghost Avatar answered Sep 23 '22 20:09

Madara's Ghost