gremo
gremo

Reputation: 48477

Metalsmith doesn't escape output of Markdown + Nunjucks

I'm stuck with this problem. When I use Markdown + Nunjucks as explained in the metalsmith-in-place Wiki the output is wrong (see below).

The default layout, note the safe filter (_layouts/base.njk):

<!DOCTYPE html>
  <html lang="en">
  <head>
    <meta charset="utf-8">
    <title>{{title}}</title>
  </head>
  <body>
    {{ contents | safe }}
  </body>

The template that is using Markdown + Nunjucks (about.md.njk):

---
title: About
layout: base.njk
---

# {{ title }}

Output:

<p>&lt;!DOCTYPE html&gt;
  &lt;html lang=&quot;en&quot;&gt;
  &lt;head&gt;
    &lt;meta charset=&quot;utf-8&quot;&gt;
    &lt;title&gt;About&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;</p>

<h1>About</h1>

<p>  &lt;/body&gt;
&lt;/html&gt;</p>

Upvotes: 0

Views: 114

Answers (1)

gremo
gremo

Reputation: 48477

Solved right after posting the question. This may be help, the problem is the order of plugins in my build.js:

Metalsmith(__dirname)
  .source('./contents')
  .destination('./build')
  .clean(true)
  .use(inPlace()) // inPlace must come BEFORE layouts!
  .use(layouts({
    directory: '_layouts',
    default: 'base.njk'
  }))
  .build(function(err) {
    if (err) throw err;
  });

Upvotes: 1

Related Questions