【问题标题】:Jekyll syntax highlighting with data variable使用数据变量突出显示 Jekyll 语法
【发布时间】:2016-10-16 17:32:59
【问题描述】:

我正在开发一个 Jekyll 页面,该页面显示了一个项目列表,其中 markdownified-syntax 突出显示代码。我有一个内容像这样的数据文件

# myitems.yaml
id: 'someID'
updated: 'someDate'

items:
  - item:
    id: "0001"
    content: "
*This is italicized*, and so is _this_. 
**This is bold**, and so is __this__. & 
Use ***italics and bold together*** if you ___have to___. 
``` html 
<script>alert() some content</script> 
<p>paragraph</p>
 ```"
  - item:
    id: "0002"
    content: "some more content"

所以items[].content 有markdown+一些代码要突出显示语法。

我在我的items.html 中使用液体作为访问这些数据

<ul>
{% for item in site.data.myitems.items %}
    <li id="{{item.id}}">
        <div>{{ item.content | strip | markdownify}}</div>
    </li>
{% endfor %}
</ul>

我正在使用 rouge 语法高亮。 markdown 已正确解析为 html,但 html 语法突出显示在 items.html 部分中不起作用。语法突出显示在帖子正文中正常工作,但在 {% include items.html %}

我得到的items 输出是:

<em>This is italicized</em>, and so is <em>this</em>. <strong>This is bold</strong>, and so is <strong>this</strong>. &amp; Use <strong><em>italics and bold together</em></strong> if you <strong><em>have to</em></strong>. <code class="highlighter-rouge">html &lt;script&gt;alert() some content&lt;/script&gt; &lt;p&gt;paragraph&lt;/p&gt;</code>

有什么帮助吗?

【问题讨论】:

    标签: jekyll liquid


    【解决方案1】:

    通过使用管道而不是常规字符串引号解决。

    -item:
      id:"0001"
      content: |
      *This is italicized*, and so is _this_. 
      **This is bold**, and so is __this__. & 
      Use ***italics and bold together*** if you ___have to___. 
      ``` html 
      <script>alert() some content</script> 
      <p>paragraph</p>
      ```
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-03-08
      • 2015-09-14
      • 2015-02-05
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多