How can I put a Liquid tag highlight in an ordered list?

荒凉一梦 提交于 2019-11-30 20:25:40

问题


This is what I want the page to be:

<ol>
  <li>first</li>
  <li>second
    <code></code>
  </li>
  <li>third</li>
</ol>

This is what I'm writing:

1. first
2. second
  {% highlight ruby %}
  code here
  {% endhighlight %}
3. third

And this is how it renders:

<ol>
  <li>first</li>
  <li>second</li>
</ol>
<div class="highlight>
  code here
</div>
<ol>
  <li>third</li>
</ol>

So how do I write and it will render as what I want it to be?


回答1:


I haven't been able to figure out how to use the "Pygments" highlighting for code blocks inside of lists. It is possible to do a basic code block without highlighting with the following:

1. first
2. second

        code here

3. third

The white space placement here is important. The way that snippet of code works, there is a a blank line between 2. second and the code here line. Additionally, there are two tabs before the code here text (Eight spaces should also work).

The output from the above using jekyll 1.0.3 with markdown: kramdown set in the _config.yml file produces:

<ol>
  <li>first</li>
  <li>
    <p>second</p>

    <pre><code> code here
</code></pre>
  </li>
  <li>third</li>
</ol> 



回答2:


I figured out a way:

1. first
2. second
 : {% highlight ruby %}
code
code
code
{% endhighlight %}
3. third

This renders as a definition list though (<dt> and <dd> tags) which is probably technically incorrect use of that markup so if you're super strict about that kind of thing you might not like it, but I haven't been able to find another way without writing your own plugin to generate lists which will completely change the way you write them.



来源:https://stackoverflow.com/questions/17995467/how-can-i-put-a-liquid-tag-highlight-in-an-ordered-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!