Code block is improperly handled and generates Liquid syntax error

A very simple code block of

```
“{%s}”
```

generates the following error

Error: Liquid syntax error (line 410): Tag '{%' was not properly terminated with regexp: /\%\}/

I am using the Minima theme with Jekyll with very few adjustments (just enough for MathJax and Mermaid). I’m guessing a tag is likely escaped incorrectly somewhere in a template.

What is at fault here? At present, there’s no way to display code that has such elements in it, such as format strings.

With Jekyll, Markdown files are fist processed by Liquid, and then Markdown, so Liquid syntax is interpreted, even within Markdown code-blocks.

To avoid the problem, the raw tag can be used to disable Liquid processing.

1 Like

Thank you for the fix!

Should it be the case that code blocks are always wrapped with the raw tag by Jekyll?

I think it depends on the language or type of code. Liquid’s delimiters ({{, {%, etc) are fairly rare to find in most code. But for nearly foolproof rendering, you could always wrap with raw.

Thank you for your help!

1 Like

Actually we have tsx and jsx code blocks in markdown. So it is I would say for ReactJS devs fairly common. And I am using Jekyll + GH Pages and I was planning on being able to see my docs both in GH and in my GH Pages all the same. But with this now I have to do:

{% raw %}
```tsx
<input style={{backgroundColor: “red”}} />
```
{% endraw %}

But I guess we cannot get around this, right?

Yes, in general one must recognize that Jekyll uses Liquid-Markdown (i.e. Markdown wrapped in Liquid markup), not pure Markdown. For example, Jekyll’s own doc uses raw-wrapping for code samples: jekyll/docs/_docs/step-by-step/02-liquid.md at master · jekyll/jekyll · GitHub

However, if Liquid-free Markdown is desired, there are probably a few ways to do it with layouts, collections, plugins/generators, etc. For example, you can create a custom Layout, where the usual {{ content }} expansion is replace by {{ page.content | markdownify }}.

In my tests with Jekyll 4.x, that avoids the need to raw-quote Liquid syntax. This would make the page rendering in Jekyll closer to GH’s viewer.

1 Like