11ty / eleventy-base-blog

A starter repository for a blog web site using the Eleventy static site generator.
https://eleventy-base-blog.netlify.app/
MIT License
1.21k stars 619 forks source link

Support literal `{{`, `{#`, `{%` tags in markdown code blocks / inline code #115

Closed olets closed 2 years ago

olets commented 2 years ago

It is not possible to use {{, {#, or {% in code blocks or inline code in markdown files without Eleventy trying to parse it. For example you can't say in ./posts/my-post.md

In zsh, `${#var}` is the length of `var` in words (arrays) or bytes

or

To set a variable in Twig, use `set`:
```twig
{% set var = 2 %}
```

(My use case: shell script examples and Twig examples in blog posts.)

Disabling pre-processing of Markdown files enables {#

// .eleventy.js

// Pre-process *.md files with: (default: `liquid`)
// markdownTemplateEngine: "njk", <-- commented out

Not a great solution if it worked, but it doesn't. Now

`{#`

will be treated literally, and compile as <code>{#</code>

but

`{{`

and

`{%`

will try to compile as Liquid.

The fundamental limitation here may be something about markdown-it, or something about Eleventy's data flow. I ran into it in this demo, lmk if I should move the issue to a different repo.

pdehaan commented 2 years ago

Correct, by default Eleventy will try and prerender the Markdown templates w/ LiquidJS. We recently discussed it in https://github.com/11ty/eleventy/discussions/2148, which includes a couple potential solutions based on your requirements.

olets commented 2 years ago

Thanks for the link!

For anyone else who hits this, keep in mind that this repo's default is Nunjucks not Liquid. Both have {% raw %)…{% endraw %} so no effective difference in the solution.