Module: Reacco::Filters::Sections
- Included in:
- Readme
- Defined in:
- lib/reacco/filters/sections.rb
Instance Method Summary collapse
-
#section_wrap(html) ⇒ Object
Wraps in sections.
Instance Method Details
#section_wrap(html) ⇒ Object
Wraps in sections.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/reacco/filters/sections.rb', line 5 def section_wrap(html) %w(h1 h2 h3 h4 h5).each do |h| nodes = html.css(h) nodes.each do |alpha| # For those affected by --hgroup, don't bother. next if alpha.ancestors.any? { |tag| tag.name == 'hgroup' } next unless alpha.parent # Find the boundary, and get the nodes until that one. omega = from_x_until(alpha, alpha.name) section_nodes = between(alpha, omega) # Create the <section>. section = Nokogiri::XML::Node.new('section', html) section['class'] = "#{alpha['class']} #{h} #{slugify alpha.content}" alpha.add_previous_sibling(section) section_nodes.each { |tag| section.add_child tag } end end html end |