Class: Asciidoctor::ListsExtended::ListMacro

Inherits:
Extensions::BlockMacroProcessor
  • Object
show all
Defined in:
lib/asciidoctor-lists-extended/extensions.rb

Overview

BlockMacroProcessor for the list-of::element[] syntax.

Supported parameters:

enhanced_rendering   — separate caption and title display (positional)
hide_empty_section   — remove the parent section if no entries found (positional)
exclude_from_toc     — omit this list from the PDF Table of Contents and outline (positional, PDF only)
exclude_from_outline — omit this list from the PDF bookmark outline only (positional, PDF only)
strip_period         — remove the trailing period from caption signifiers, e.g. "Table 1." → "Table 1" (positional)
split_caption        — render signifier and title separately with indentation in list entries (positional, PDF only)
caption_prefix       — override the caption prefix (e.g. "Figure")
title                — override the list heading
entry_indent         — (named, numeric) override theme entry indent (pt)
first_entry_margin   — (named, numeric) override theme first-entry margin (pt)

Example:

list-of::image[]
list-of::table[hide_empty_section]
list-of::listing[caption_prefix="Code",title="Code Examples"]

Instance Method Summary collapse

Instance Method Details

#process(parent, target, attrs) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/asciidoctor-lists-extended/extensions.rb', line 36

def process(parent, target, attrs)
  uuid = SecureRandom.uuid
  # Positional flags like [enhanced_rendering] may be stored under integer or string keys
  pos_flags = (1..10).flat_map { |i| [attrs[i], attrs[i.to_s]] }.compact
  ListMacroAttributes[uuid] = {
    element:            target,
    enhanced_rendering:   attrs['enhanced_rendering']   || pos_flags.include?('enhanced_rendering'),
    hide_empty_section:   attrs['hide_empty_section']   || pos_flags.include?('hide_empty_section'),
    exclude_from_toc:     attrs['exclude_from_toc']     || pos_flags.include?('exclude_from_toc'),
    exclude_from_outline: attrs['exclude_from_outline'] || pos_flags.include?('exclude_from_outline'),
    strip_period:         attrs['strip_period']         || pos_flags.include?('strip_period'),
    split_caption:        attrs['split_caption']        || pos_flags.include?('split_caption'),
    # site — force document-wide scope regardless of nesting depth.
    # Needed in Antora assembled PDFs where pages are shifted one level deep
    # (what was == Section in the source becomes === Subsection in the assembled
    # document), causing scope_node_for to mis-classify the macro as chapter-scoped.
    scope_global:         attrs.key?('site')            || pos_flags.include?('site'),
    caption_prefix:       attrs['caption_prefix'],
    title:                attrs['title'],
    entry_indent:         attrs['entry_indent']&.to_f,
    first_entry_margin:   attrs['first_entry_margin']&.to_f,
  }
  create_paragraph parent, uuid, {}
end