Search code examples
htmlcssnode.jsghost-blog

Stop html from being rendered inside code blocks


My problem is that HTML is being rendered inside code tags. In ghost blog I have had no issues using code tags. Except from HTML, which is actually rendered.

This example from below is actually rendered.

<pre><code>
<div>some text</div>
<input value="even this is rendered"></input>
</code></pre>

If I use 4-spaces inline it works fine. I'm using the default style layout.

Looking at the official markdown-documentation this is supposed to work. http://daringfireball.net/projects/markdown/syntax


Solution

  • <code> isn't supposed to stop HTML being rendered. It means "Present this in a way that indicates it is code" not "Don't treat this HTML as HTML".

    Use character references for characters with special meaning in HTML if you want them to be displayed (&amp;, &lt;, etc).

    The Markdown documentation says:

    Within a code block, ampersands (&) and angle brackets (< and >) are automatically converted into HTML entities.

    … but code block means "When the markdown source is indented by 4 characters" not "When wrapped in pre/code".