Module: Coradoc::Docx::Transform::OrderedContent
- Included in:
- Rules::HeadingRule, Rules::ListItemRule, Rules::ParagraphRule, Rules::TableRule
- Defined in:
- lib/coradoc/docx/transform/ordered_content.rb
Overview
Utility for iterating paragraph content in document order.
OOXML paragraphs have separate arrays for runs, hyperlinks, SDTs, etc. but ‘element_order` (from lutaml-model mixed_content) preserves the interleaved sequence. This module provides a single method to walk paragraph content in the correct order.
Used by ParagraphRule, ListItemRule, and HeadingRule.
Instance Method Summary collapse
-
#extract_plain_text(children) ⇒ String
Flatten children array to plain text string.
-
#transform_paragraph_content(paragraph, context) ⇒ Array
Iterate paragraph inline content in document order.
Instance Method Details
#extract_plain_text(children) ⇒ String
Flatten children array to plain text string.
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/coradoc/docx/transform/ordered_content.rb', line 34 def extract_plain_text(children) children.map do |c| case c when String then c when CoreModel::InlineElement then c.content.to_s when CoreModel::Block then c.content.to_s else c.to_s end end.join end |
#transform_paragraph_content(paragraph, context) ⇒ Array
Iterate paragraph inline content in document order.
20 21 22 23 24 25 26 27 28 |
# File 'lib/coradoc/docx/transform/ordered_content.rb', line 20 def transform_paragraph_content(paragraph, context) order = paragraph.is_a?(Uniword::Wordprocessingml::Paragraph) ? paragraph.element_order : nil if order && !order.empty? transform_ordered(paragraph, order, context) else transform_sequential(paragraph, context) end end |