I need to manually replace html tags with entities.
You don’t need to do it manually, but you do need to do it before you send the HTML to the client.
The usual approaches for solving the problem are:
- Use Find & Replace in an editor
- Write your content in a different language (such as Markdown, the approach used on Stackoverflow), convert it to HTML and then insert it in to your template.
Is there a nice solution (maybe in JS) to disallow the exec of html in a
<code>
tag?
No.
Any such solution would have some pretty serious limitations.
If it ran client side, it couldn’t stop the content of the element being parsed so:
- It would have to deal with the results of the HTML being parsed to a DOM and then serialised back to HTML (which would normalise it).
- It couldn’t deal with HTML that wasn’t allowed inside
<code>
such as<p>
If it ran server side it would either need a very specialised parser to figure out where the code element started and finished (and probably couldn’t handle the case where the desired output was <code></code></code>
at all) or would suffer the same limitations as the JS version.
3
solved display RAW HTML Code in tags