gpt4 book ai didi

html - jekyll 中的 Jekyll 代码

转载 作者:太空狗 更新时间:2023-10-29 13:34:33 25 4
gpt4 key购买 nike

我正在为 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 标签内还是反过来都没关系:

{%raw%}
```
{% for post in site.posts %}
{% if post.categories contains '<categoryname>' %}
<h2>
<a href="{{ post.url }}">{{ post.title }}</a>
</h2>
{% endif %}
{% endfor %}
```
{%endraw%}

关于html - jekyll 中的 Jekyll 代码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22044488/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com