Markdown: continue numbered list

Markdown

Markdown Problem Overview


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. Is there any way to prevent that behaviour?

Desired output:

1. item 1
2. item 2

```
Code block
```

3. item 3

Produced output:

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

Markdown Solutions


Solution 1 - Markdown

Use four spaces to indent content between bullet points

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

Produces:

  1. item 1

  2. item 2

    Code block
    
  3. item 3

Solution 2 - Markdown

As an extension to existing answers. For those trying to continue a numbered list after something other than a code block. For example a second paragraph. Just indent the second paragraph by at least 1 space.

Markdown:

1. one
2. two

 three
3. four

Output:

  1. one

  2. two

    three

  3. four

Solution 3 - Markdown

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).

  2. item 1

  3. item 2

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

  5. 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:

  6. item 1

  7. item 2

    Code block

  8. item 3

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

Solution 4 - Markdown

Macmade's solution doesn't work for me anymore on my Jekyll instance on Github Pages anymore but I found this solution on an issue for the kramdown github repo. For OP's example it would look like this:

1. item 1
2. item 2

```
Code block
```

{:start="3"}
3. item 3

Solved my issues handily.

Solution 5 - Markdown

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>

Solution 6 - Markdown

If you happen to be using the Ruby gem redcarpet to render Markdown, you may still have this problem.

You can escape the numbering, and redcarpet will happily ignore any special meaning:

1\. Some heading

text text
text text

text text

2\. Some other heading

blah blah

more blah blah

Solution 7 - Markdown

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

Solution 8 - Markdown

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).

Solution 9 - Markdown

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

Solution 10 - Markdown

Put the list numbers in parentheses instead of followed by a period.

(1) item 1
(2) item 2

code block

(3) item 3

Solution 11 - Markdown

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 markdown.markdown(some_text, extensions=['sane_lists'])

Solution 12 - Markdown

You can try to add a backslash (\) before the period (1\. item 1), which disables the list auto-numbering. Note: this will remove left side indentation.

1. item 1

def call_of_duty()
   return press_f()

3. item 3

print("fus ro dah")

7. item 7

print("Omae Wa Mou Shindeiru")

10. item 10


From the link source:

3\. Put on shoes
2\. Open door
1\. Step outside

renders

3. Put on shoes
2. Open door
1. Step outside

Solution 13 - Markdown

If you want to have text aligned to preceding list item but avoid having "big" line break, use two spaces at the end of a list item and indent the text with some spaces.

Source: (dots are spaces ;-) of course)

1.·item1··
····This is some text
2.item2

Result:

  1. item1
    This is some text
  2. item2

Solution 14 - Markdown

In CommonMark Spec has a rules about this

1. foo
2. bar
7) baz

Generate this HTML

<ol>
<li>foo</li>
<li>bar</li>
</ol>
<ol start="3">
<li>baz</li>
</ol>

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionorschiroView Question on Stackoverflow
Solution 1 - MarkdownMacmadeView Answer on Stackoverflow
Solution 2 - MarkdownDavidTView Answer on Stackoverflow
Solution 3 - MarkdownDan DascalescuView Answer on Stackoverflow
Solution 4 - MarkdownKhalilRavannaView Answer on Stackoverflow
Solution 5 - Markdownuser3505838View Answer on Stackoverflow
Solution 6 - MarkdownfqxpView Answer on Stackoverflow
Solution 7 - MarkdownbrilloutView Answer on Stackoverflow
Solution 8 - MarkdowniuvbioView Answer on Stackoverflow
Solution 9 - MarkdownNestor MarinView Answer on Stackoverflow
Solution 10 - MarkdownlomzherView Answer on Stackoverflow
Solution 11 - MarkdownAlexView Answer on Stackoverflow
Solution 12 - MarkdownDmitriy ZubView Answer on Stackoverflow
Solution 13 - MarkdownJardaView Answer on Stackoverflow
Solution 14 - MarkdownDamon AbdielView Answer on Stackoverflow