Markdown: continue numbered list

前端 未结 12 1573
予麋鹿
予麋鹿 2020-12-04 04:39

In the following markdown code I want item 3 to start with list number 3. But because of the code block in between markdown starts this list item as a new list.

相关标签:
12条回答
  • 2020-12-04 05:17

    I solved this problem on Github separating the indented sub-block with a newline, for instance, you write the item 1, then hit enter twice (like if it was a new paragraph), indent the block and write what you want (a block of code, text, etc). More information on Markdown lists and Markdown line breaks.

    Example:

    1. item one
    2. item two

      this block acts as a new paragraph, above there is a blank line

    3. item three

      some other code

    4. item four
    0 讨论(0)
  • 2020-12-04 05:18

    Note that there are also a number of extensions available that will fix this behaviour for specific contexts of Markdown use.

    For example, sane_lists extension of python-markdown (used in mkdocs, for example), will recognize numbers used in Markdown lists. You just need to enable this extension arkdown.markdown(some_text, extensions=['sane_lists'])

    0 讨论(0)
  • 2020-12-04 05:19

    If you don't want the lines in between the list items to be indented, like user Mars mentioned in his comment, you can use pandoc's example_lists feature. From their docs:

    (@)  My first example will be numbered (1).
    (@)  My second example will be numbered (2).
    
    Explanation of examples.
    
    (@)  My third example will be numbered (3).
    
    0 讨论(0)
  • 2020-12-04 05:28

    Source;

    <span>1.</span> item 1<br/>
    <span>2.</span> item 2
    ```
    Code block
    ```
    <span>3.</span> item 3
    


    Result;

    1. item 1
    2. item 2 Code block 3. item 3

    0 讨论(0)
  • 2020-12-04 05:36

    Notice how in Macmade's solution, you can see an extra line of code above the "Code block".

    Here are two better solutions:

    1. Indent the code block by an extra 4 spaces (so usually 8, in this nested list example, 12). This will put the code in a <pre> element. On SO, you can even specify syntax highlight with a
      <!-- language: lang-js --> indented by 4 spaces (+1 here due to the nested list).

      1. item 1
      2. item 2

        Code.block('JavaScript', maybe)?
        
      3. item 3

    2. Or, just put the Code block within backticks and indent by 4 spaces (here, 1 extra because of the nested list). You'll get a regular indented text paragraph, with a <code> element inside it. This one you can't syntax-highlight:

      1. item 1
      2. item 2

        Code block

      3. item 3

    Note: you can click "edit" on this answer to see the underlying Markdown code. No need to save ;)

    0 讨论(0)
  • 2020-12-04 05:37

    If you use tab to indent the code block it will shape the entire block into one line. To avoid this you need to use html ordered list.

    1. item 1
    2. item 2

    Code block

    <ol start="3">
      <li>item 3</li>
      <li>item 4</li>
    </ol>
    
    0 讨论(0)
提交回复
热议问题