0

我想用 Markdown 语言对标题、部分和小节进行编号。因此 TOC 如下所示:

1. Heading1
2. Heading2
   2.1 Section1
   2.2 Section2
        2.2.1 Subsection1
        2.2.2 Subsection2

我正在使用 MKDOCS 创建我的静态网页 apython 包。是否有任何降价扩展可以做到这一点?

刚开始使用markdown语言,欢迎任何帮助和建议。

4

2 回答 2

1

标头编号不是 HTML 可以做的,但有标准的方法可以用 css 来做

如果您还没有这样做,请在mkdocs.yml文件中添加此声明:

extra_css: [specific.css]

然后specific.css在目录中的文件中写这个docs(这是建议的css代码,逐字逐句,所以我让你检查它是否适合你):

body {
counter-reset : h2;
    }

h2 {
counter-reset : h3;
    }

h3 {
counter-reset : h4;
    }

h4 {
counter-reset : h5;
    }

h5 {
counter-reset : h6;
    }

article h2:before {
content : counter(h2,decimal) ". ";
counter-increment : h2;
    }

article h3:before {
content : counter(h2,decimal) "." counter(h3,decimal) ". ";
counter-increment : h3;
    }

article h4:before {
content : counter(h2,decimal) "." counter(h3,decimal) "." counter(h4,decimal) ". ";
counter-increment : h4;
    }

article h5:before {
content : counter(h2,decimal) "." counter(h3,decimal) "." counter(h4,decimal) "." counter(h5,decimal) ". ";
counter-increment : h5;
    }

article h6:before {
content : counter(h2,decimal) "." counter(h3,decimal) "." counter(h4,decimal) "." counter(h5,decimal) "." counter(h6,decimal) ". ";
counter-increment : h6;
    }

h2.nocount:before, h3.nocount:before, h4.nocount:before, h5.nocount:before, h6.nocount:before {
content : "";
counter-increment : none;
    }
于 2018-07-02T15:42:48.723 回答
0

以下基于 Python 的 CLI 工具枚举您的降价中的标题

https://github.com/a4vision/enumerate-markdown

它将标题添加到降价文件。例如:

输入

# header
text
## sub-header
# header

输出

# 1. header
text
## 1.2 sub-header
# 2. header
于 2022-01-03T22:57:37.690 回答