在 Jekyll 中的 Markdown 代码块内转义双花括号
我正在使用 Jekyll 创建一个文档站点,其中我试图记录一些包含类似车把语法的代码。例如{{foo}}
。问题是 Jekyll 使用液体标签,无论我做什么,我的双卷发都会被液体处理器撕掉。
顺便说一下,我使用 kramdown 作为 markdown 处理器。
这是我尝试过的:
{% highlight html linenos %}
Hello, my name is {{name}}.
{% endhighlight %}
这个完全删除了 {{name}} 部分,因为它认为它是对液体变量的引用。
我也尝试过这个:
{% highlight html linenos %}
Hello, my name is \{\{name\}\}.
{% endhighlight %}
在这种情况下,我试图转义大括号,但结果是斜杠被渲染到页面中。
我什至尝试过这个:
{% highlight html linenos %}
Hello, my name is <span>{</span>{name}}.
{% endhighlight %}
不可否认,这个非常愚蠢。在本例中,因为我已将语法指定为 html(它需要如此),所以 span 标记将呈现到页面中。
那么我到底该如何解决这个问题呢?
I'm using Jekyll to create a documentation site wherein I am trying to document some code that contains handlebars-like syntax. For example {{foo}}
. The problem is that Jekyll uses liquid tags and no matter what I do, my double curlies are getting ripped out by the liquid processor.
By the way, I'm using kramdown as the markdown processor.
Here is something I've tried:
{% highlight html linenos %}
Hello, my name is {{name}}.
{% endhighlight %}
This one removes the {{name}} section completely because it thinks it's a reference to a liquid variable.
I also tried this:
{% highlight html linenos %}
Hello, my name is \{\{name\}\}.
{% endhighlight %}
In this case, I'm trying to escape the curly braces but the result is that the slashes get rendered into the page.
I even tried this:
{% highlight html linenos %}
Hello, my name is <span>{</span>{name}}.
{% endhighlight %}
Admittedly this one was pretty dumb. In this case, because I've specified the syntax as html (which it needs to be), the span tag gets rendered into the page.
So how in the world can I resolve this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您正在寻找
{% raw %}
标签。You're looking for the
{% raw %}
tag.您可以使用
{% raw %}
来确保内容未被Jekyll修改:但是,请注意,这不是代码块。您将需要额外的代码格式以使您的内容呈现为代码:
You can use
{% raw %}
to ensure content is unmodified by Jekyll:However, note that this is not a code block. You will need additional code formatting to make your content render as code:
使用 jekyll 的代码是:
With jekyll the code is:
供将来参考:使用普通的
{% raw %}
和{% endraw %}
只是第二好的解决方案,因为如果您在普通 github 上查找 Markdown,就会显示这些解决方案.com。最好的方法是将
{% raw %}
和{% endraw %}
放在 HTML 注释中:由于 HTML 注释,Github 将其视为注释。在 Github 页面中,原始标签将阻止解析标签之间的大括号。
For future references: using plain
{% raw %}
and{% endraw %}
is only the second best solution since those are shown if you look up the Markdown on normal github.com.The best way is to put
{% raw %}
and{% endraw %}
in HTML comments:Due to the HTML comments it is seen by Github as a comment. In Github pages the raw tags will prevent the parsing of the curly brackets in between the tags.
这在 jekyll 中有效:
This works in jekyll: