Class: Rbpptx::Paragraph
- Inherits:
-
Object
- Object
- Rbpptx::Paragraph
- Defined in:
- lib/rbpptx/paragraph.rb
Overview
A paragraph (+<a:p>+) inside a shape’s text body.
Paragraphs hold a sequence of Runs separated optionally by soft line breaks (+<a:br>+). The #text accessor mirrors Shape#text restricted to this paragraph: runs joined as-is, breaks rendered as “n”. Since paragraphs map 1:1 to <a:p> elements, paragraph boundaries are not rendered as “n” here — that is Shape#text‘s job.
Constant Summary collapse
- A_NS =
"http://schemas.openxmlformats.org/drawingml/2006/main".freeze
Instance Method Summary collapse
-
#initialize(node:, slide: nil) ⇒ Paragraph
constructor
A new instance of Paragraph.
-
#runs ⇒ Array<Run>
<a:r> children in document order.
-
#text ⇒ String
Concatenated text.
Constructor Details
#initialize(node:, slide: nil) ⇒ Paragraph
Returns a new instance of Paragraph.
15 16 17 18 |
# File 'lib/rbpptx/paragraph.rb', line 15 def initialize(node:, slide: nil) @node = node @slide = end |
Instance Method Details
#runs ⇒ Array<Run>
Returns <a:r> children in document order. <a:fld> (field) and <a:br> (line break) elements are not included.
22 23 24 |
# File 'lib/rbpptx/paragraph.rb', line 22 def runs @node.xpath("./a:r", "a" => A_NS).map { |r| Run.new(node: r, slide: @slide) } end |
#text ⇒ String
Returns concatenated text. Run text appears verbatim; <a:br> between runs is rendered as “n”.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/rbpptx/paragraph.rb', line 28 def text buf = +"" @node.children.each do |child| next unless child.namespace&.href == A_NS case child.name when "r" t = child.at_xpath("./a:t", "a" => A_NS) buf << t.text if t when "br" buf << "\n" end end buf end |