https://discuss.asciidoctor.org/Paragraph-numbering-tp3697p3890.html
Alex,
Thanks for the kind words about Asciidoctor and Asciidoctor PDF. I certainly hope that you'll be able to make use of it for your virtuous cause!
Numbering paragraphs is easily achieved using a Treeprocessor extension. A Treeprocessor runs after the blocks in the document have been parsed into an internal structure. At that point, you can modify the content to add automatic numbering of paragraphs.
There are two ways to achieve this. You can either insert text at the start of the paragraph or you can give the paragraph a title. Either way will enable you to inject numbering into the content dynamically.
Here's a quick implementation to show you the idea.
[source,ruby]
----
require 'asciidoctor'
require 'asciidoctor/extensions'
class NumberParagraphsTreeprocessor < Asciidoctor::Extensions::Treeprocessor
def process document
document.find_by(context: :paragraph).each_with_index do |p, idx|
pnum = idx + 1
# number paragraph using title
p.title = %(#{pnum}.)
# or insert number into paragraph
p.lines.first.prepend %(#{pnum}. )
end
end
end
Extensions.register do
treeprocessor NumberParagraphsTreeprocessor
end
----
Keep in mind that the Treeprocessor can alter the document regardless of what output format you are producing.
I recommend that you use a Treeprocessor approach for this use case as opposed to modifying the source document as this metadata should not concern the author (at least that's my understanding).