如何在asciidoc中编号代码清单?(How to number code listings in asciidoc?)

我在ascidoc上写博客,并希望代码清单能够自动编号,例如

Listing 1.3 The Hello World code ... Listing 1.4 Some other code sample

是否有我可以为整个文本设置的属性,以便asciidoc自动编号代码清单?

I'm writing a blog in ascidoc and would like the code listings to be automatically numbered, e.g.

Listing 1.3 The Hello World code ... Listing 1.4 Some other code sample

Is there an attribute that I can set for the entire text so asciidoc would automatically number code listings?

最满意答案

在asciidoctor用户手册(列表块)中并不清楚,但为了让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的讨论。

It is not that clear in the asciidoctor user-manual (Listing Blocks), but in order for asciidoctor to number the listing you need to:

add a caption to each block set the listing-caption attribute at the begining of your document

Example:

:listing-caption: Listing .The Hello World code ---- //TODO: add hello world code ---- .Some other code sample ---- //TODO: Some other code sample ----

Controlling the way the listing blocks are numbered (1.1, 1.2 in your example) is not that easy. There is a discussion on GitHub for that.

如何在asciidoc中编号代码清单?(How to number code listings in asciidoc?)

我在ascidoc上写博客,并希望代码清单能够自动编号,例如

Listing 1.3 The Hello World code ... Listing 1.4 Some other code sample

是否有我可以为整个文本设置的属性,以便asciidoc自动编号代码清单?

I'm writing a blog in ascidoc and would like the code listings to be automatically numbered, e.g.

Listing 1.3 The Hello World code ... Listing 1.4 Some other code sample

Is there an attribute that I can set for the entire text so asciidoc would automatically number code listings?

最满意答案

在asciidoctor用户手册(列表块)中并不清楚,但为了让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的讨论。

It is not that clear in the asciidoctor user-manual (Listing Blocks), but in order for asciidoctor to number the listing you need to:

add a caption to each block set the listing-caption attribute at the begining of your document

Example:

:listing-caption: Listing .The Hello World code ---- //TODO: add hello world code ---- .Some other code sample ---- //TODO: Some other code sample ----

Controlling the way the listing blocks are numbered (1.1, 1.2 in your example) is not that easy. There is a discussion on GitHub for that.