列表编号 Jupyter notebook markdown

List numbering Jupyter notebook markdown

我尝试为学生创建教程。我想对我问他们的问题进行编号,但在这两者之间我想添加信息来介绍问题。如何制作一个自动编号的列表,每次放置文本时都不会重置编号。例如:

This is some info.
1. This is question one.

This is more info.
2. This is question two.

给出输出:

这是一些信息。

  1. 这是第一个问题。

这是更多信息。

  1. 这是第二题。

虽然您可以 "fake it"(见下文),但标准 Markdown 无法直接实现这一点。事实上 rules 状态:

It’s important to note that the actual numbers you use to mark the list have no effect on the HTML output Markdown produces. ... The point is, if you want to, you can use ordinal numbers in your ordered Markdown lists, so that the numbers in your source match the numbers in your published HTML. But if you want to be lazy, you don’t have to.

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.

那个未来从未正式到来。然而,一些不同的 Markdown 实现可能会提供这样的功能作为非默认选项。不幸的是,这种情况很少见(而且我不记得它们是哪些实现)。

无论如何,你会遇到另一个问题。我不清楚你想要的输出如何有效 HTML。本质上,您要求的是嵌套在列表中的列表项之外的段落。那将是无效的 HTML:

<ol>
  <p>This is some info.</p>
  <li>This is question one.</li>
  <p>This is more info.</p>
  <li>This is question two.</li>
</ol>

就是说,它(几乎)会按照您的意愿显示(非列表项也会缩进)。

    This is some info.

  1. This is question one.
  2. This is more info.

  3. This is question two.

我不推荐它,但您可以将其用作原始 HTML。也许您可以找到其他一些方法或格式来表示您的数据。

如果您的 Markdown 实现支持它,我考虑过建议使用嵌套在定义列表中的有序列表(虽然不是标准的,但此功能在实现中非常常见且一致,尽管它可能不是默认启用的)。它确实为您提供了正确的嵌套,但如果不连续的数字仍然存在,则会出现同样的问题。但是,如果您手动添加数字并对其进行转义,以便它们不被解释为列表项,则它的工作方式如下:

This is some info.
: 1\. This is question one.

This is more info.
: 2\. This is question two.

呈现为:

<dl>
<dt>This is some info.</dt>
<dd>1. This is question one.</dd>
<dt>This is more info.</dt>
<dd>2. This is question two.</dd>
</dl>

并显示为:

This is some info.
    1. This is question one.
This is more info.
    2. This is question two.

有趣的是,由于 SO 删除了定义列表上的(通常默认的)缩进,在我尝试在上面的演示中伪造它时,我意识到有一个更简单的解决方案应该适用于所有 Markdown 实现。只需使用段落、手动编号和不间断空格来强制缩进:

This is some info.

&nbsp; &nbsp; 1. This is question one.

This is more info.

&nbsp; &nbsp; 2. This is question two.

请注意,不间断空格会导致 Markdown 无法将这些行视为列表项,从而无需转义它们。以上呈现为:

<p>This is some info.</p>
<p>&nbsp; &nbsp; 1. This is question one.</p>
<p>This is more info.</p>
<p>&nbsp; &nbsp; 2. This is question two.</p>

并显示为:

This is some info.

    1. This is question one.

This is more info.

    2. This is question two.

与期望的不一样,但是jupyter在我写的时候停止了重新编号 1) 2) 3) 等等

')' 似乎禁用了由 Jupyter 的 markdown 完成的重新编号。租用 jupyter 版本 5.0.0 运行 python 3.5.2.

我们可以通过多种方式在 Jupyter notebook 中以 markdown 模式创建列表。我自己推荐的最简单的方法很简单: 只需在列表中的项目之前附加 * (确保在星号后包含 space)。例如:

* one
* two
* three

输出:

  • one
  • two
  • three

另一种方法,您只需键入任何 numberdot,例如 1.,然后键入列表中的项目。

1. one
2. two
3. three

所以会看到输出为:

  1. one
  2. two
  3. three

如果您想更改列表格式,例如将点转换为数字或将数字转换为点 只需简单地以适当的格式更改一个元素,整个列表就会转换。

例如

 1. one
 * two
 * three

输出会

  1. one
  2. two
  3. three

* one
2. two
3. three

输出:

  • one
  • two
  • three