Put some HTML inside the <pre class = "prettyprint-override"> tag?
2 answers
If you have no control over the released HTML, you can still encode it on the client side.
Here's how you could avoid all the markup inside tags <pre>using the jQuery library:
$(function() {
var pre = $('pre');
pre.html(htmlEncode(pre.html()));
});
function htmlEncode(value){
return $('<div/>').text(value).html();
}
Edit : on request, the same code without using jQuery:
function encodePreElements() {
var pre = document.getElementsByTagName('pre');
for(var i = 0; i < pre.length; i++) {
var encoded = htmlEncode(pre[i].innerHTML);
pre[i].innerHTML = encoded;
}
};
function htmlEncode(value) {
var div = document.createElement('div');
var text = document.createTextNode(value);
div.appendChild(text);
return div.innerHTML;
}
And run encodePreElementsafter loading the DOM:
<body onLoad='encodePreElements()'>
<pre>Foo <b>bar</b></pre>
</body>
+9