【问题标题】:Three-level nested list in kramdownkramdown 中的三级嵌套列表
【发布时间】:2015-06-12 12:57:19
【问题描述】:

我一直在尝试创建一个如下所示的嵌套列表(使用 kramdown,用于 GitHub 页面),但 HTML 输出不是语义的;二级列表使用段落代替列表元素,三级列表项使用代码块。

1. Do something.

2. Do something else.

    a. If the reverse-Pi separation gauge is set to `OFF` you can follow
       the following procedure.

        i. Use the flux capacitor on Mondays, Tuesdays and Thursdays, but
           only if you have not done so already.

        ii. Do not use the flux capacitor if it's raining, because the
            universe will implode.

    b. If the reverse-Pi separation gauge is set to `ON` then you
       should follow Procedure 42.

3. Go back to doing things.

上面生成了以下 HTML...

<ol>
  <li>
    <p>Do something.</p>
  </li>
  <li>
    <p>Do something else.</p>

    <p>a. If the reverse-Pi separation gauge is set to <code>OFF</code> you can follow
    the following procedure.</p>

    <pre><code> i. Use the flux capacitor on Mondays, Tuesdays and Thursdays, but
    only if you have not done so already.

 ii. Do not use the flux capacitor if it's raining, because the
     universe will implode.
</code></pre>

    <p>b. If the reverse-Pi separation gauge is set to <code>ON</code> then you
    should follow Procedure 42.</p>
  </li>
  <li>
    <p>Go back to doing things.</p>
  </li>
</ol>

我已尝试更改缩进甚至删除项目之间的空白行,但无法使其按预期工作。

1.而不是它们的实际数字替换所有列表“子弹”确实可以生成结构正确的HTML(感谢Scroog1离线建议);然后可以使用 CSS 使输出的 HTML 列表具有所需的list-style-type。但是,这感觉与 Markdown 的 "it should be readable as plain text" philosophy 相反,所以我想知道是否有任何方法可以使其工作并且在 Markdown 版本中看起来像预期的那样?

(我想可以说,在这种特殊情况下,HTML 是我的文档的唯一格式,人们会阅读,最好让机器进行编号,并且使用 CSS 而不是内联样式更简洁由降价处理器生成以实现所需的列表格式,但我很好奇上述失败是否可能是我对 kramdown 的滥用,或者可能是错误或设计决策。)

【问题讨论】:

    标签: markdown github-pages kramdown


    【解决方案1】:

    将它们全部设为有序列表

    1. Do something.
    
    2. Do something else.
    
        1. If the reverse-Pi separation gauge is set to `OFF` you can follow
           the following procedure.
    
            1. Use the flux capacitor on Mondays, Tuesdays and Thursdays, but
               only if you have not done so already.
    
            2. Do not use the flux capacitor if it's raining, because the
                universe will implode.
    
        2 If the reverse-Pi separation gauge is set to `ON` then you
           should follow Procedure 42.
    
    3. Go back to doing things.
    

    然后应用样式

    li li{
        list-style-type: lower-alpha;
    }
    
    li li li{
        list-style-type: lower-roman;
    }
    

    MDN on CSS

    【讨论】:

    • 谢谢你;它似乎最接近纯文本友好(比我建议让所有标记都简单1.)。有趣的是,我使用ol olol ol ol 作为我的CSS 选择器,具有相同的list-style-type 属性。我读了the spec,虽然它指出选择器应该显示为list-item,但这些示例还将list-style-type 属性应用于ulol 元素,所以看起来使用任何一个都是有效的.
    【解决方案2】:

    Kramdown documentation 没有显示任何支持除数字 1、2、3 之外的有序列表的示例......

    它使用第一个列表指示符的值来确定列表是有序的还是无序的,您可以应用与列表内联的样式类,如下所示:

    1. {:.cls} This item has the class "cls".
    2. {:.cls} This item also as the class "cls".
    

    这仍然主要是作为纯文本可读的,并且将使您的 CSS 更易于管理(数字 2-x 上的样式类可能不是必需的,我从未尝试过)。

    【讨论】:

    • 这是一个有趣的方法;谢谢。但是,就个人而言,我认为我投票支持的答案对纯文本更友好一些。指向手册很有帮助;似乎表明他们没有宣传三级嵌套作为一项功能 - 很高兴知道。 [如果我有足够的积分来投票,我会简单地这样做,但想确认你的贡献。 ]
    • 不用担心。当您获得更多代表时,您总是可以回到这里。 ;)
    猜你喜欢
    • 1970-01-01
    • 2018-04-05
    • 1970-01-01
    • 2013-01-29
    • 2020-10-29
    • 2018-07-14
    • 2021-11-12
    • 2021-08-09
    • 2022-11-17
    相关资源
    最近更新 更多