Class: Coradoc::Docx::Transform::Rules::HeadingRule
- Inherits:
-
Coradoc::Docx::Transform::Rule
- Object
- Coradoc::Docx::Transform::Rule
- Coradoc::Docx::Transform::Rules::HeadingRule
- Includes:
- OrderedContent
- Defined in:
- lib/coradoc/docx/transform/rules/heading_rule.rb
Overview
Transforms heading paragraphs to CoreModel::StructuralElement.
Heading detection uses StyleResolver which checks pStyle values (like “Heading1”, “heading 2”) and outline levels.
This rule is NOT registered in the RuleRegistry — instead, the ToCoreModel orchestrator dispatches to it directly after checking the style resolver. This avoids the problem of matches() needing context to determine if a paragraph is a heading.
Instance Method Summary collapse
Methods included from OrderedContent
#extract_plain_text, #transform_paragraph_content
Methods inherited from Coradoc::Docx::Transform::Rule
Instance Method Details
#apply(paragraph, context) ⇒ Object
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/coradoc/docx/transform/rules/heading_rule.rb', line 23 def apply(paragraph, context) level = context.style_resolver.heading_level(paragraph) || 1 title = extract_title(paragraph, context) id = extract_bookmark_id(paragraph) CoreModel::StructuralElement.new( element_type: 'section', level: level, title: title, id: id ) end |
#matches?(_element) ⇒ Boolean
19 20 21 |
# File 'lib/coradoc/docx/transform/rules/heading_rule.rb', line 19 def matches?(_element) false # Never auto-matched; orchestrator dispatches directly end |