我正在为Jekyll创建一个鸟瞰视图教程,在
Github页面上托管(在我的Jekyll上运行的博客上).所以,我想在那里放一些代码.如果我把以下内容:
- {% for post in site.posts %}
- {% if post.categories contains '<categoryname>' %}
- <h2>
- <a href="{{ post.url }}">{{ post.title }}</a>
- </h2>
- {% endif %}
- {% endfor %}
解决方法
Jekyll使用的{%…%}语法是
Liquid templating engine的一部分.要转义这些标记,并按字面显示它们,您应该使用
raw
tag.
您可能希望将其与代码块的markdown语法结合使用.使用Redcarpet,您可以使用三重反引号语法.如果你将反引号放在原始标签内或反之亦然:
- {%raw%}
- ```
- {% for post in site.posts %}
- {% if post.categories contains '<categoryname>' %}
- <h2>
- <a href="{{ post.url }}">{{ post.title }}</a>
- </h2>
- {% endif %}
- {% endfor %}
- ```
- {%endraw%}