如何对 asciidoc 中的代码清单进行编号?
How to number code listings in asciidoc?
我正在用 ascidoc 写博客,希望代码清单能够自动编号,例如
Listing 1.3 The Hello World code
...
Listing 1.4 Some other code sample
是否有我可以为整个文本设置的属性,以便 asciidoc 自动为代码列表编号?
在 asciidoctor user-manual (Listing Blocks) 中不是很清楚,但是为了让 asciidoctor 对列表进行编号,您需要:
- 为每个块添加标题
- 在文档的开头设置
listing-caption
属性
示例:
:listing-caption: Listing
.The Hello World code
----
//TODO: add hello world code
----
.Some other code sample
----
//TODO: Some other code sample
----
控制列表块的编号方式(在您的示例中为 1.1、1.2)并不容易。 GitHub 上有一个讨论。
我正在用 ascidoc 写博客,希望代码清单能够自动编号,例如
Listing 1.3 The Hello World code
...
Listing 1.4 Some other code sample
是否有我可以为整个文本设置的属性,以便 asciidoc 自动为代码列表编号?
在 asciidoctor user-manual (Listing Blocks) 中不是很清楚,但是为了让 asciidoctor 对列表进行编号,您需要:
- 为每个块添加标题
- 在文档的开头设置
listing-caption
属性
示例:
:listing-caption: Listing
.The Hello World code
----
//TODO: add hello world code
----
.Some other code sample
----
//TODO: Some other code sample
----
控制列表块的编号方式(在您的示例中为 1.1、1.2)并不容易。 GitHub 上有一个讨论。