I have an Express app using the default Jade view engine. When I try to render HTML as-is in a <pre>
element, it gets rendered as actual DOM elements instead of literal characters.
h1 Code Sample
pre
code
<div>some text</div>
Output:
<h1>Code Sample</h1>
<pre>
<code>
<div>some text</div>
</code>
</pre>
How do I escape the HTML so that it gets rendered as follows?
<h1>Code Sample</h1>
<pre>
<code>
<div>some text</div>
</code>
</pre>
As an addition, here is another use case which you need to consider:
If you are extrapolating the HTML content using the #{...}
, it will still give the wrong output.
For that use case, you need the !{...}
alternative.
So,
div= varname
becomes
div!= varname
And
div #{varname} is extrapolated badly
becomes
div !{varname} is extrapolated perfectly
Jade uses the bang to force unescaped output. So you turn regular output to unescaped output with the following construct: !=
If your content is inside an div tag you could do the following:
div!= content
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With