Liquid Exception

Posted on By ᵇᵒ

在写Jekyll Directory structure的_includes时,使用了 {% include file.ext %} 这个字符串作为示例,介绍如何包含_includes下的文件.
提交后收到了Github的编译报错邮件

The page build failed for the `master` branch with the following error:
A file was included in `_posts/2017-06-30-blog.md` that is a symlink or does not exist in your `_includes` directory. For more information, see
https://help.github.com/articles/page-build-failed-file-is-a-symlink/.

For information on troubleshooting Jekyll see:
https://help.github.com/articles/troubleshooting-jekyll-builds

If you have any questions you can contact us by replying to this email.

查看提示https://help.github.com/articles/page-build-failed-file-is-a-symlink/,发现错误原因是Jekyll以为我要在文章里包含_includes下的file.ext文件,但是这个文件却不存在,从而编译失败.

事实上,这里我只是想举例表达 {% include file.ext %} 这个字符串,并不想去调用file.ext这个文件,很明显Jekyll使用的Liquid把这个特定格式的字符串给转换了.

试了很多方法,无论是标记成行内还是区块都不行.在{和%之间加空格倒是可以解决,但是这样我想表达的效果就变了,如果有人复制过去作为代码使用就会出问题.

最后搜索到了这个issue,samselikoff的方法完美解决了问题.
在文章里这样写
{% raw %} {% include file.ext %} {% endraw %}
liquid转换后就成了 {% include file.ext %} .

但是这里又有个问题,在写这篇文章的时候我没办法把
{% raw %} {{ include file.ext }} {% endraw %}
作为raw text显示出来,
因为第一个{% endraw %} 总是和{% raw %})配对去了,没办法把{% endraw %}本身作为raw text给予显示.

在请教了Liquid写文档的小哥Adam Hollett之后得到了答案把{}和%用HTML实体替换掉就可以了.
{ 对应为 {
% 对应为 %
} 对应为 }

写到这里又有个问题:laughing:,&在Markdown里属于特殊字符,如果想显示也需要用HTML实体&替换掉https://daringfireball.net/projects/markdown/syntax#autoescape

所以你看到的这句话
  { 对应为 {
其实在我写的Markdown文件里是这样子的
  { 对应为 &amp#123;

而你看到的这句话
  { 对应为 {
对应的Markdown又是这样子的
  { 对应为 {

而你看到的这句话
  { 对应为 {
对应的Markdown…

因为&对应的HTML实体&开头又包含自身,所以咱们可以无限玩下去
疯了有木有:joy:

最后,附上HTML Entity链接
http://www.ascii.cl/htmlcodes.htm
https://en.wikipedia.org/wiki/List_of_XML_and_HTML_character_entity_references
https://www.w3.org/TR/html4/sgml/entities.html