Class: Coradoc::Docx::Transform::Rules::RunRule
- Inherits:
-
Coradoc::Docx::Transform::Rule
- Object
- Coradoc::Docx::Transform::Rule
- Coradoc::Docx::Transform::Rules::RunRule
- Defined in:
- lib/coradoc/docx/transform/rules/run_rule.rb
Overview
Transforms w:r (Run) elements to InlineElement or String.
Runs with formatting become CoreModel::InlineElement nodes. Plain runs (no formatting properties) return their text directly.
A single run may carry multiple formatting properties (e.g., bold + italic). The most specific one wins for format_type, while the text content is preserved.
Uses effective_run_properties (when available) to resolve style inheritance: explicit properties > paragraph style’s rPr > basedOn chain. Falls back to run.properties for backward compatibility.
Instance Method Summary collapse
Methods inherited from Coradoc::Docx::Transform::Rule
Instance Method Details
#apply(run, context) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/coradoc/docx/transform/rules/run_rule.rb', line 25 def apply(run, context) # Delegate non-text children (breaks, drawings, footnotes, etc.) non_text = extract_non_text_children(run, context) return non_text.first if non_text.any? && run.text.nil? text = run.text&.content.to_s return '' if text.empty? && non_text.empty? props = effective_props(run) return text if plain_run?(props) fmt = format_type(props, run, context) return text unless fmt CoreModel::InlineElement.new( format_type: fmt, content: text ) end |
#matches?(element) ⇒ Boolean
20 21 22 23 |
# File 'lib/coradoc/docx/transform/rules/run_rule.rb', line 20 def matches?(element) defined?(Uniword::Wordprocessingml::Run) && element.is_a?(Uniword::Wordprocessingml::Run) end |