Markdown:在列表内进行连续列表的正确方法是什么? [英] Markdown: What's the proper way to do a continued list inside of a list?

查看:198
本文介绍了Markdown:在列表内进行连续列表的正确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在GFM中的列表内执行连续列表的正确方法是什么?

What's the proper way to do a continued list inside of a list in GFM?

目标:

  1. 一个
  1. 一个
  2. 两个

  • 两个

  • Two

    1. 三个
    2. 四个


  • 我查看了有关续号列表


    I've looked at common posts regarding continued number lists and relevant issues but haven't seen anyone ask this question yet.

    推荐答案

    从技术上讲,您不能这样做. Markdown是HTML的子集,而HTML不提供这种功能.但是,您可以使用<ol start="3">之类的东西在HTML中进行伪造,该伪造实际上是告诉列表以3而不是默认的1开始编号.

    Technically you can't. Markdown is a subset of HTML and HTML does not offer such a feature. However, you can fake it in HTML with something like <ol start="3"> which essentially tells a list to start numbering with 3 rather than the default 1.

    当然,您总是可以退回到原始HTML,但让我们继续仅在Markdown中实现这一目标.是否可以在Markdown中执行此操作取决于所使用的Markdown实现.

    Of course, you could always fall back to raw HTML, but lets proceed with the goal of accomplishing this in Markdown only. Whether you can do this in Markdown depends on which Markdown implementation you are using.

    传统的降价规则状态:

    请务必注意,您用来标记 列表对Markdown产生的HTML输出没有影响.

    It’s important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces.

    ...

    但是,如果您确实使用了惰性列表编号,则仍应启动 编号为1的列表.在将来的某个时候,Markdown可能会 支持以任意数字开头的有序列表.

    If you do use lazy list numbering, however, you should still start the list with the number 1. At some point in the future, Markdown may support starting ordered lists at an arbitrary number.

    由此可见,当前尚无法实现所需的行为.但是,如果暗示的更改要发生,事情可能会有所不同...

    From that, it is clear that the desired behavior is currently not possible. However, if the hinted change were to happen, things might be different...

    事实证明,Github扩展的Commonmark确实支持以任意数字开头的有序列表.正如规范所述:

    As it turns out, Commonmark, which Github extends, does support starting ordered lists at an arbitrary number. As the spec states:

    有序列表的起始编号由列表编号确定 其初始列表项.后续列表项的数量为 忽略.

    The start number of an ordered list is determined by the list number of its initial list item. The numbers of subsequent list items are disregarded.

    鉴于上述情况,似乎以下内容会产生所需的输出:

    Given the above, It might seem that the following would produce the desired output:

    1. One
        1. one
        2. two
    2. Two
        3. three
        4. four 
    

    但是,作为的实现).

    But, as Babelmark demonstrates, that only works for a few implementations (notice the implementations which include <ol start="3"> in the output).

    部分问题是父列表在嵌套列表的紧前一行包含一个段落(内容为Two).因此,如果您在不同的块级元素之间添加空白行,就像这样:

    Part of the problem is that the parent list contains a paragraph (with content Two) ont he line immediately before the nested list. So if you add a blank line between the different block level elements, like this:

    1. One
    
        1. one
        2. two
    
    2. Two
    
        3. three
        4. four
    

    然后更多的实现可以正确地看到嵌套列表.具体来说,如):

    Then more implementations properly see the nested list. Specifically, as Babelmark demonstrates, this causes Commonmark to parse the list as you desire. In fact, you get this output (note the <ol start="3">):

    <ol>
        <li>
            <p>One</p>
            <ol>
                <li>one</li>
                <li>two</li>
            </ol>
        </li>
        <li>
            <p>Two</p>
            <ol start="3">
                <li>three</li>
                <li>four</li>
            </ol>
        </li>
    </ol>
    

    事实上,我检查了一下,在GitHub上它可以正常工作.

    And, in fact, I checked and this works correctly in GitHub.

    这篇关于Markdown:在列表内进行连续列表的正确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    相关文章
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆