I have a string myString="<pre class='ql-syntax'><code><html><body>Will this work?</body></html></code></pre>"
which needs to be rendered in a webpage such that the content inside the <code>
block is encoded so it shows up as is.
$('<div/>').html(htmlString).html()
removes the html
and body
tags and outputs the following:
<pre class="ql-syntax"><code>Will this work?</code></pre>
What I want the output to be is:
<pre class="ql-syntax"><code><html>hello</html></code></pre>
so on the webpage, the entire content which is inside the code block renders.
How do I encode only the part of the myString which is between the <code>
block?
I am fetching the myString from the database, so I don't have any control over how I construct the myString. I can manipulate it however I want to make sure the html inside the code block renders as is.
Will this work?
` is left. You want the output to be `Will this work?
`? – Garrett Kadillak Apr 23 '17 at 21:00