Yakov Fain
Yakov Fain

Reputation: 12376

How to number code listings in 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?

Upvotes: 2

Views: 1205

Answers (1)

Jmini
Jmini

Reputation: 9507

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.

Upvotes: 3

Related Questions