Skip to content


Escaping of Tag Content #12

semperos opened this Issue · 2 comments

3 participants


I believe in Hiccup the content portion of tags is not HTML-escaped by default. In Crate, when I provide a string with raw HTML inside it, it appears that the Google methods used by Crate createTextNode and/or setTextContent do escape the content string.

I need to be able to pass raw HTML strings as the content to elements. How can I go about this using Crate?


This isn't a bug in crate. The google-closure createTextNode is not escaping the text either, it's a plain wrapper over the Document createTextNode(). The latter method does not interpret or parse it's input, which is why HTML entity characters are printed literally. What to do? Since this question was posted 5 months ago, I gather you've found a solution. In any case, if you're working with UTF-8 encoded documents, send the equivalent unicode notation for the HTML entity,

e.g. &ldquo -> \u201C ...


This threw me too. It's because crate returns dom nodes instead of strings like hiccup. It uses createTextNode to do this. Conveniently, it accepts dom nodes as node content so you can do stuff like this:

(crate/html [:div (.htmlToDocumentFragment goog.dom "<span>foo</span><strong>bar</strong>")])
=> <div><span>foo</span><strong>bar</strong></div>
@bmaddy bmaddy referenced this issue

improve readme #18

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.