Module: Wedge::HTML
- Includes:
- Methods
- Defined in:
- lib/wedge/html.rb
Class Method Summary collapse
-
.[](raw_html) ⇒ Object
Parse HTML into a Nokogiri object.
Methods included from Methods
Class Method Details
.[](raw_html) ⇒ Object
Parse HTML into a Nokogiri object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/wedge/html.rb', line 9 def [](raw_html) return unless server? # remove all the starting and trailing whitespace raw_html = raw_html.strip if raw_html[/\A<!DOCTYPE/] || raw_html[/\A<html/] Nokogiri::HTML(raw_html) else parsed_html = Nokogiri::HTML.fragment(raw_html) if parsed_html.children.length >= 1 parsed_html.children.first else parsed_html end end end |