Chris Draycott-Wheatley

Escaping Nunjuck tags in Markdown using Eleventy

When recently writing an article on including Nunjuck templates in Markdown using Eleventy I needed a way to not only execute Nunjuck templates but to also show the code in that template.

As it turns out Nunjucks has a raw tag that can be wrapped around code to ensure it isn't executed.

Wrapping your code examples in {% raw %} and {% endraw %} tags will ensure the Nunjuck tags aren't executed.

For inline code that looks like this {% raw %}`{{ variable | filter }}`{% endraw %}.

And for block of code, like this:

{% raw %}
```
{{ variable | filter }}
```
{% endraw %}

Hopefully this helps those of you struggling to show your Eleventy code examples on your Eleventy blog, like I was.