# Code block is improperly handled and generates Liquid syntax error

**URL:** <https://talk.jekyllrb.com/t/code-block-is-improperly-handled-and-generates-liquid-syntax-error/7599>\
**Category:** Help\
**Created:** [August 23, 2022, 6:19am UTC](https://talk.jekyllrb.com/t/code-block-is-improperly-handled-and-generates-liquid-syntax-error/7599 "2022-08-23T06:19:00Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![bmitc](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/bmitc/32/5023_2.png) [@bmitc](https://talk.jekyllrb.com/u/bmitc)\
**Post date:** [August 23, 2022, 6:19am UTC](https://talk.jekyllrb.com/t/code-block-is-improperly-handled-and-generates-liquid-syntax-error/7599/1 "2022-08-23T06:19:00Z")

</div>

A very simple code block of

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

generates the following error

```auto
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.

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [August 23, 2022, 1:02pm UTC](https://talk.jekyllrb.com/t/code-block-is-improperly-handled-and-generates-liquid-syntax-error/7599/2 "2022-08-23T13:02:04Z")

</div>

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](https://shopify.github.io/liquid/tags/template/#raw).

---

<div class="post-metadata">

**Author:** ![bmitc](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/bmitc/32/5023_2.png) [@bmitc](https://talk.jekyllrb.com/u/bmitc)\
**Post date:** [August 26, 2022, 11:55pm UTC](https://talk.jekyllrb.com/t/code-block-is-improperly-handled-and-generates-liquid-syntax-error/7599/3 "2022-08-26T23:55:32Z")

</div>

Thank you for the fix!

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

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [August 27, 2022, 1:20am UTC](https://talk.jekyllrb.com/t/code-block-is-improperly-handled-and-generates-liquid-syntax-error/7599/4 "2022-08-27T01:20:18Z")

</div>

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`.

---

<div class="post-metadata">

**Author:** ![bmitc](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/bmitc/32/5023_2.png) [@bmitc](https://talk.jekyllrb.com/u/bmitc)\
**Post date:** [September 5, 2022, 10:37pm UTC](https://talk.jekyllrb.com/t/code-block-is-improperly-handled-and-generates-liquid-syntax-error/7599/5 "2022-09-05T22:37:10Z")

</div>

Thank you for your help!

---

<div class="post-metadata">

**Author:** ![kasir-barati](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/kasir-barati/32/6117_2.png) [@kasir-barati](https://talk.jekyllrb.com/u/kasir-barati)\
**Post date:** [October 25, 2024, 7:08pm UTC](https://talk.jekyllrb.com/t/code-block-is-improperly-handled-and-generates-liquid-syntax-error/7599/6 "2024-10-25T19:08:53Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![chuckhoupt](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.jekyllrb.com/chuckhoupt/32/523_2.png) [@chuckhoupt](https://talk.jekyllrb.com/u/chuckhoupt)\
**Post date:** [October 26, 2024, 3:17pm UTC](https://talk.jekyllrb.com/t/code-block-is-improperly-handled-and-generates-liquid-syntax-error/7599/7 "2024-10-26T15:17:20Z")

</div>

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](https://github.com/jekyll/jekyll/blob/master/docs/_docs/step-by-step/02-liquid.md)

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.
