How to include "{%%}" in markdown file when using jekyll?

I use Jekyll to publish blogs. When I write "{% ...%}" in my markup files, it seems that "{% ...%}" will be parsed by Liquid. But sometimes this is not what I want, and can cause errors. So, how to correctly include texts like "{% ...%}" in my message (.md file)?

I checked the Liquid docs and found out that I can use the Block Tag {% raw %} ... {% end raw %} to include raw text between them. However, I do not think this is a good idea. Since if the markdown file was not analyzed by Liquid (for example, in some environment other than Jekyll), this will leave unused {% raw%} in my text.

Correct me if I say something wrong.

PS: I use GitHub pages for hosting and they disable plugins.

+6
source share
3 answers

One thing to keep in mind about the Jekyll and GitHub pages is that you can always create your site locally (by running jekyll build ), pass it to your repo and ask GitHub from there from there. This way you can use (or create) a plugin that allows you to have what you want .: P

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

+6
source

You can use HTML objects { and } for { and } . Not the most accurate, but it does not use {% raw %} or relies on plugins.

+1
source

I managed to get this working using the following code:

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

In the above snippet, I include the sidebar that I wrote in Markdown.

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

0
source

Source: https://habr.com/ru/post/949730/


All Articles