Escaping of Tag Content #12

Closed
semperos opened this Issue May 25, 2012 · 3 comments

Comments

Projects
None yet
3 participants
@semperos

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?

@zussitarze

This comment has been minimized.

Show comment
Hide comment
@zussitarze

zussitarze Nov 5, 2012

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 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 ...

@bmaddy

This comment has been minimized.

Show comment
Hide comment
@bmaddy

bmaddy Dec 31, 2012

Contributor

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>
Contributor

bmaddy commented Dec 31, 2012

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 Dec 31, 2012

Merged

improve readme #18

@semperos

This comment has been minimized.

Show comment
Hide comment
@semperos

semperos Jul 27, 2016

Haven't touched or looked at this in a long time, closing.

Haven't touched or looked at this in a long time, closing.

@semperos semperos closed this Jul 27, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment