5

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?

Witek
  • 5,670
  • 7
  • 39
  • 59

1 Answers1

11

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)]
Community
  • 1
  • 1
Madara's Ghost
  • 158,961
  • 49
  • 244
  • 292
  • Thank you very much. But I use reagent which is hiccup-like but not realy hiccup. Therefor there is no hiccup.util namespace :-( – Witek Sep 21 '16 at 17:21
  • You have not. I have changed my question. Sorry ;-) – Witek Sep 21 '16 at 17:33
  • 2
    @Witek That's OK, next time, if you noticed that you have an edit that would invalidate existing answers, please ask a new question, linking to the old one, with explaining the difference. – Madara's Ghost Sep 21 '16 at 18:14
  • It looks like there is no longer a `raw-string` function in the `hiccup.util` namespace: http://weavejester.github.io/hiccup/hiccup.util.html Edit: looks like it's part of v2: https://cljdoc.org/d/hiccup/hiccup/2.0.0-alpha2/api/hiccup.util#raw-string – Scott Aug 28 '20 at 01:27