使用 Jekyll 时获得 "Liquid Exception: Liquid syntax error"

Getting an "Liquid Exception: Liquid syntax error" while using Jekyll

I 运行 bundle exec jekyll serve --trace on Windows 10. 我收到以下控制台消息:

D:\MyPorfolio\perrot.github.io>bundle exec jekyll serve
Configuration file: D:/MyPorfolio/perrot.github.io/_config.yml
            Source: D:/MyPorfolio/perrot.github.io
       Destination: D:/MyPorfolio/perrot.github.io/_site
 Incremental build: disabled. Enable with --incremental
      Generating...
  Liquid Exception: Liquid syntax error (line 8): Syntax Error in 'for loop' - Valid syntax: for [item] in [collection] in 2018-09-14-Rendering a python dict in jinja2.markdown

杰基尔 3.7.3 |错误:Liquid 语法错误(第 8 行):'for loop' 中的语法错误 - 有效语法:[collection]

中的 [item]

有谁知道如何解决这个问题?提前致谢。

文件 2018-09-14-Rendering a python dict in jinja2.markdown content is:

---
layout: post
title:  "Rendering a python dict in jinja2"
date:   2018-09-14 00:01:57 +0800
categories: python jinja2
---

    ```python
    url_list = [{'target': 'http://10.58.48.103:5000/', 'clicks': '1'}, 
                {'target': 'http://slash.org', 'clicks': '4'},
                {'target': 'http://10.58.48.58:5000/', 'clicks': '1'},
                {'target': 'http://de.com/a', 'clicks': '0'}]
    #Python 2.7

    {% for key, value in url_list.iteritems() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    #Python 3

    {% for key, value in url_list.items() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    ```

Liquid 会尝试处理您的源代码,尤其是 jinja2 控制标签,为此您需要告诉 Liquid 避免使用 raw 标签处理它:

{% highlight python %}
{% raw %}
   url_list = [{'target': 'http://10.58.48.103:5000/', 'clicks': '1'}, 
                {'target': 'http://slash.org', 'clicks': '4'},
                {'target': 'http://10.58.48.58:5000/', 'clicks': '1'},
                {'target': 'http://de.com/a', 'clicks': '0'}]
    #Python 2.7

    {% for key, value in url_list.iteritems() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}
    #Python 3

    {% for key, value in url_list.items() %}
        <li>{{ value["target"] }}</li> 
    {% endfor %}

{% endraw %}
{% endhighlight %}

1 - {% raw %} 标记是 this post and this post.

中 python 代码的解决方案的一部分

2 - 解决方案的另一部分can be a bug in the way Jekyll manages excerpts

删除代码中的空行,它将起作用。