Class: Arrolio::EmbeddedBlockExtractor

Inherits:
Object
  • Object
show all
Defined in:
lib/arrolio/embedded_block_extractor.rb

Overview

Extracts block-level elements (notes, examples) that are nested inside paragraph elements. In standoc presentation XML, notes can appear as children of

, not just as direct children of . Without extraction, these embedded blocks are silently dropped during inline run collection.

Constant Summary collapse

SECTION_NAMES =
['clause', 'terms', 'definitions', 'annex', 'annex2'].freeze

Instance Method Summary collapse

Constructor Details

#initialize(rules, converter_registry) ⇒ EmbeddedBlockExtractor

Returns a new instance of EmbeddedBlockExtractor.



12
13
14
15
# File 'lib/arrolio/embedded_block_extractor.rb', line 12

def initialize(rules, converter_registry)
  @rules = rules
  @converter_registry = converter_registry
end

Instance Method Details

#extract(elem) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/arrolio/embedded_block_extractor.rb', line 17

def extract(elem)
  blocks = []
  block_names = embedded_block_names
  return blocks if block_names.empty?

  elem.each_recursive do |descendant|
    next unless block_names.include?(descendant.name)
    next if inside_section?(descendant, elem)

    mapping_entry = @rules['element_mapping'][descendant.name]
    converter = @converter_registry[mapping_entry['content_type']]
    next unless converter

    result = yield(converter, descendant, mapping_entry)
    blocks.concat(result)
  end
  blocks
end