Search code examples
markdowndocpad

My markdown files are showing html tags in the browser


I am using the DocPad static site generator. I have run docpad install marked on Command Line.

My markdown file about.html.md contains this:
I like long walks on the beach. _Plus I rock at DocPad!_

When I look at the site in the browser, I see the actual tags:

<p>I like long walks on the beach. <em>Plus I rock at DocPad!</em></p>

Obviously what I want to see is:

I like long walks on the beach. Plus I rock at DocPad!

I am using the Nunjucks tempting engine through the consolidate plugin if that makes any difference...


Solution

  • According to the documentation, autoescaping is turned on by default in the Nunjucks templating engine as a security precaution (typical of most templating engines). If you are passing HTML to the template and you want that HTML to be rendered without escaping, then you need to tell the template that it is "safe":

    {{ foo | safe }}
    

    Alternatively, you could globally turn escaping off, but that is generally not recommended. If you want to do that anyway, the docs state that you can "pass the autoescape option as false to the Environment object":

    var env = nunjucks.configure('/path/to/templates', { autoescape: false });
    

    I'm not familiar with the consolidate plugin for DocPad, but presumably passing { autoescape: false } as an option to consolidate would accomplish the same thing.