fgnass / domino

Server-side DOM implementation based on Mozilla's dom.js
BSD 2-Clause "Simplified" License
764 stars 118 forks source link

How to keep the encoded string in html ? #157

Closed kuncevic closed 4 years ago

kuncevic commented 4 years ago

I have failed an issue on angular universal repo https://github.com/angular/universal/issues/1484 but it is turned out to be domino's default behavior.

Basically my issue that I have a use-case where I want to keep encoded string in my html.

as per this comment here is a current behavior, the string gets decoded by domino:

const domino = require("domino");

const window = domino.createWindow('<body>&#097;</body>', '');
window.document.serialize(); 
// "<html><head></head><body>a</body></html>"

Do you have any ideas how to achieve that?

cscott commented 4 years ago

Nope, not possible under the official W3C spec: https://html.spec.whatwg.org/#serialising-html-fragments

The text node does not contain entities. You could try using a "style, script, xmp, iframe, noembed, noframes, or plaintext element" as the standard says. But otherwise the DOM does not (by spec) represent entities as anything other than the character they represent.