Class: Asciidoctor::ListsExtended::ListTreeprocessor
- Inherits:
-
Extensions::Treeprocessor
- Object
- Extensions::Treeprocessor
- Asciidoctor::ListsExtended::ListTreeprocessor
- Defined in:
- lib/asciidoctor-lists-extended/extensions.rb
Overview
Treeprocessor that runs after the full document AST is built.
Responsibilities:
1. Auto-generate IDs for all captioned/titled elements referenced by
list-of:: macros. This eliminates the need for manual [#anchor] on
every block.
2. For HTML5/other backends: replace UUID placeholder paragraphs with
xref-based content (delegated to HtmlRenderer).
3. For PDF backend: leave UUID placeholder paragraphs in place so that
PDFConverterWithLists can locate and render them during allocate_toc /
ink_toc.
Instance Method Summary collapse
Instance Method Details
#process(document) ⇒ Object
74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/asciidoctor-lists-extended/extensions.rb', line 74 def process(document) return if ListMacroAttributes.empty? # Auto-generate IDs for all elements referenced by list-of:: macros. # Works for both HTML and PDF — the IDs must exist before either renderer runs. ListMacroAttributes.each_value do |config| document .find_by(traverse_documents: true, context: config[:element].to_sym) .each do |element| next unless element.caption || element.title next if element.has_role?('exclude-from-listof') next if element.id element.id = SecureRandom.uuid document.catalog[:refs][element.id] = element end end # PDF backend: UUID placeholders are handled by PDFConverterWithLists. return if document.backend == 'pdf' # HTML5 and other backends: replace UUID placeholders with xref content. HtmlRenderer.new.render(document) end |