在下面的降价代码中,我希望项目3从列表3开始。但由于markdown之间的代码块将此列表项作为一个新列表启动。有没有办法防止这种行为?

期望的输出:

1. item 1
2. item 2

```
Code block
```

3. item 3

产生的输出:

第一项 第二项

代码块

项目3


当前回答

如果使用制表符缩进代码块,它会将整个代码块塑成一行。为了避免这种情况,你需要使用html有序列表。

第一项 第二项

代码块

<ol start="3">
  <li>item 3</li>
  <li>item 4</li>
</ol>

其他回答

在CommonMark Spec中对此有一个规则

1. foo
2. bar
3) baz

生成这个HTML

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

注意在Macmade的解决方案中,你可以在“代码块”上方看到额外的一行代码。

这里有两个更好的解决方案:

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). item 1 item 2 Code.block('JavaScript', maybe)? item 3 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: item 1 item 2 Code block item 3

注意:你可以在这个答案上点击“编辑”来查看底层Markdown代码。不需要保存;)

作为现有答案的延伸。对于那些试图在代码块以外的东西后面继续编号列表的人。比如第二段。第二段缩进至少一个空格。

Markdown:

1. one
2. two

 three
3. four

输出:

一个 两个 三个 四个

请注意,还有许多可用的扩展可以修复Markdown使用的特定上下文的这种行为。

例如,python-markdown的sane_lists扩展(例如,在mkdocs中使用)将识别Markdown列表中使用的数字。您只需要启用这个扩展markdown。减记(some_text、扩展= [' sane_lists '])

源;

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

结果;

1. 第一项 2. 第二项 代码块 3.项目3