Class: Nokogiri::HTML::Document

Inherits:
Object
  • Object
show all
Defined in:
lib/nexmo_developer/app/extensions/nokogiri/html/document.rb

Instance Method Summary collapse

Instance Method Details

#split_htmlObject



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/nexmo_developer/app/extensions/nokogiri/html/document.rb', line 4

def split_html
  sections = []

  css('body').children.each_with_index do |child, index|
    if index.zero? || %w[h1 h2 h3 h4 h5 h6].include?(child.name)
      sections << [child]
    else
      sections.last << child unless child.text == "\n"
    end
  end

  sections.map! do |section|
    Nokogiri::HTML(section.map(&:to_html).join)
  end

  sections
end