javascriptsyntax-highlightinggoogle-code-prettify

Why is Google Code Prettify rendering the actual code


I'm trying to display a html template as markup in a code block

<div>
    <pre class="prettyprint lang-html">
        <code>
            <%= template %>
        </code>
    </pre>
</div>

But the template actually renders in the browser, rather than the markup displaying in a code block.

I've included the CDN script in my body tag

<script src="https://cdn.rawgit.com/google/code-prettify/master/loader/run_prettify.js"></script>

Solution

  • You still need to escape html entities to prevent them from being displayed on the page. &, <, and > need to be changed to &amp;, &lt;, and &gt;.