tags:

views:

68

answers:

0

Right now, splitting the HTML document to small pieces like this: (regular expression simplified - skipping header tag content and closing tag)

document.at('body').inner_html.split(/<\s*h[2-6][^>]*>/i).collect do |fragment|
  Nokogiri::HTML(fragment)
end

Is there more easy way to perform that splitting?

The document is very simple, just headers, paragraphs and formatted text in it. For example:

<body>
<h1>Main</h1>
<h2>Sub 1</h2>
<p>Text</p>
-----
<h2>Sub 2</h2>
<p>Text</p>
-----
<h3>Sub 2.1</h3>
<p>Text</p>
-----
<h3>Sub 2.2</h3>
<p>Text</p>
</body>

For that sample, I need to get four pieces.