Method: Prawn::Text::Formatted::Parser.array_paragraphs

Defined in:
lib/prawn/text/formatted/parser.rb

.array_paragraphs(array) ⇒ Object

:nodoc:



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/prawn/text/formatted/parser.rb', line 96

def self.array_paragraphs(array) #:nodoc:
  paragraphs = []
  paragraph = []
  previous_string = "\n"
  scan_pattern = /[^\n]+|\n/
  array.each do |hash|
    hash[:text].scan(scan_pattern).each do |string|
      if string == "\n"
        paragraph << hash.dup.merge(:text => "\n") if previous_string == "\n"
        paragraphs << paragraph unless paragraph.empty?
        paragraph = []
      else
        paragraph << hash.dup.merge(:text => string)
      end
      previous_string = string
    end
  end
  paragraphs << paragraph unless paragraph.empty?
end