How can I put a Liquid tag highlight in an ordered

2019-02-16 03:38发布

问题:

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.