Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  37] [ 5]  / answers: 1 / hits: 19015  / 10 Years ago, thu, february 27, 2014, 12:00:00

How do I put my HTML code so that highlight.js prettify it ?



I tried



<pre>
<code>
<!-- HTML Prettify -->
<div>
<pre class=pre-code-ception><code> haha </code></pre>
</div>
</code>
</pre>


I did put at the end of my file :



<script type=text/javascript>
hljs.initHighlightingOnLoad();
</script>


But everything is shown as plain HTML.


More From » html

 Answers
35

Oh, I think I understand the problem. You need to escape the HTML within the <code> element, otherwise it will be interpreted as HTML instead of text (you want the HTML displayed literally, not interpreted as part of the webpage structure).



Change every < to &lt; and > to &gt;, as well as any other special HTML characters in your code sample. (If you're generating the page on the fly, most languages have a utility function to escape the HTML for you.)


[#72259] Wednesday, February 26, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
carlo

Total Points: 705
Total Questions: 87
Total Answers: 101

Location: Indonesia
Member since Wed, Jul 7, 2021
3 Years ago
;