lazd / DOMly

The fast template system that creates and clones DOM nodes
MIT License
53 stars 9 forks source link

HTML entities are not passed through as-is #20

Closed lazd closed 9 years ago

lazd commented 9 years ago

HTML entities will end up as their text equivalent.

The following template:

{ and } are entities that resolve to { and }.

Ends up doing this:

document.createTextNode("{ and } are entities that resolve to { and }.\n");

However, this doesn't seem to be causing problems, and passing the actual entity to createTextNode will not result in the expected behavior.

Thanks to @cif for reporting this behavior.

lazd commented 9 years ago

Because we're actually parsing the template HTML with cheerio/htmlparser2, entities are turned into their text equivalent... DOMly dumps strings into text nodes, and since entities are HTML, not text, they'll never be rendered if you do something like document.createTextNode('}'). I don't think there's a way around this, and I'm pretty sure we won't have any HTML document encoding issues as a result.

I think this should end up in the documentation somewhere in case others notice this behavior or find problems that result from it.

cif commented 9 years ago

In this example, compiled template is definitely behaving as though the entities are their respective text equivalents:

https://gist.github.com/cif/dbab85c186ab398f888a

lazd commented 9 years ago

Thanks for the report @cif, I'm going to go ahead and close this as DOMly never deals with innerHTML, just textContent.