6
votes

I am using Jekyll to post blogs. When I write "{%...%}" in my markdown files, it seems that the "{%...%}" will be parsed by Liquid. But sometimes that is not what I want, and may cause errors. So what's the proper way to include texts like "{%...%}" in my post content(the .md file)?

I checked the Liquid docs and learned I can use the Block Tag {% raw %} ... {% end raw %} to include raw text between. However, I don't think this a good idea. Because if the markdown file was not parsed by Liquid (e.g., in some environment other than Jekyll), this will leave unused {% raw %} in my text.

Correct me if I said something wrong.

P.S.: I use GitHub Pages for hosting and they disable plugins.

3

3 Answers

7
votes

One thing to remember about Jekyll and GitHub pages is that you can always build your site locally (by running jekyll build), commit it to your repo and have GitHub serve it from there. So you can use (or create) a plugin that'll enable you to have what you want. :P

On the other hand, I think it's really too much trouble to not use the {% raw %}. If -- and only if -- you're going to use these markdown files somewhere else, you can pass them through a script (or a sed command) and sweep away these tags.

1
votes

You could use HTML entities { and } for { and }. Not the tidiest but it doesn't use {% raw %} or rely on plugins.

0
votes

I was able to get this working using the following code:

{% capture sidebar %}{% include sidebar.md %}{% endcapture %}
{{ sidebar | markdownify }}

It the above snippet I am including a sidebar that I wrote in Markdown.

Here is a link to the original GitHub comment where I got this idea from.