1

我在 Jekyll 中使用Kramdown 的 ToC 生成,我想知道我可以让它以某种方式支持自动编号,以便这个降价:

## Header A

### Subheader

## Header B

变成这个 HTML:

<h2>1 Header A</h2>
<h3>1.1 Subheader</h3>
<h2>2 Header B</h2>

显然这可以在CSS或 JavaScript 中完成,但我正在寻找 Markdown-> HTML only 解决方案。

4

3 回答 3

2

请注意 kramdown 文档中的这一部分:

应用于原始列表的所有属性也将应用于生成的 TOC 列表,如果没有设置 ID,它将获得 markdown-toc 的 ID。

所以,只需更换

- This list will contain the toc (it doesn't matter what you write here)
{:toc}

1. This list will contain the toc (it doesn't matter what you write here)
{:toc}

获得编号的 ToC 而不是未编号的。

于 2015-04-09T13:02:08.173 回答
0

正如在kramdown 配置中看到的那样,无法在本地获得它。插件方式可以解决这个问题。

于 2015-01-30T21:59:48.350 回答
0

您可以使用https://github.com/A4Vision/enumerate-markdown

pip install enumerate-markdown
markdown-enum filename.md <minimal level> filenameoutput.md

最低级别可以是 1、2、3 等,具体取决于您希望将 #1 分配给哪个标题级别。

github 没有提到要求的最低级别选项,但在我的情况下,它只提供一个级别。

示例 - 输入

# header 1
text
## header 2
text
# header 3
text

输出

# 1.  header 1
text
## 1.1  header 2
text
# 2.  header 3
text

Markdown / Rdiscount 中的编号标题是否可能?

由于标题现在已编号,它们将在 TOC 和您的标题中编号。

于 2021-06-30T14:43:44.923 回答