I have the following HTML:
<p>This contains an HTML space entity  .</p>
I need to serialize this HTML to text along with HTML entities as their existing code (spaces added to prevent SO from rendering literal characters):
< p >This contains an HTML space entity & #160;.< / p >
When serializing the HTML the HTML entities are rendered instead of converted to their code/text form:
new XMLSerializer().serializeToString(element)
I've looked in to other methods of converting HTML code to text including innerHTML
though I haven't managed to determine any direct means to outputting the HTML code that exists without it being modified by the browser.
I'm also open to replacing HTML entities with a createTreeWalker
if need be though I'd prefer a more direct approach. No frameworks. Suggestions please?