'Numbered lists that share numbering across sections

In Asciidoctor, is it possible to have multiple numbered lists, split across different sections, that all share numbering (perhaps by setting [start={counter:list-counter}]). Something like this:

== Section A

. item 1
. item 2

== Section B

[start={list-counter}]
. item 3
. item 4

== Section C

[start={list-counter}]
. item 5
. item 6

which should render as this:

Section A
1. item 1
2. item 2

Section B
3. item 3
4. item 4

Section C
5. item 5
6. item 6

Unfortunately I don't think there's a way to have a variable that counts the number of previous list items. Or is there?

I could hack this by placing a [.invisible]#{counter:list-counter}# on every list item, but hopefully there is a better way.



Solution 1:[1]

Continuing a list over multiple section is not a standard task, I think the clean way to go is definitely with a counter.

Instead of an ordered list you could instead use a Description list, it does not look the same but brings some flexibility and the main idea is there:

== Section A

{counter:list-counter}):: item 1
{counter:list-counter}):: item 2

== Section B

{counter:list-counter}):: item 3
{counter:list-counter}):: item 4

== Section C

{counter:list-counter}):: item 5
{counter:list-counter}):: item 6

Solution 2:[2]

Here's another hack:

= Document

== Section A

. item 1
. item 2
+
[discrete]
== Section B

. item 3
. item 4
+
[discrete]
== Section C

. item 5
. item 6

That gets the list items to have the correct item numbers, but the "discrete" headings are indented. You could use some CSS customization (say via docinfo files) to outdent them.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Kiroul
Solution 2 eskwayrd