(X)HTML parser.
Parses a String and returns an REXML::Document with the (X)HTML content.
For example:
html = "<p>paragraph</p>" parser = HTMLParser.new(html) puts parser.document
Requires a patched version of SGMLParser.
# File lib/html/htmlparser.rb, line 378 def handle_comment(data) end
# File lib/html/htmlparser.rb, line 374 def handle_data(data) @current.children << HTML::Text.new(@current, 0, 0, data) end
# File lib/html/htmlparser.rb, line 381 def handle_special(data) end
# File lib/html/htmlparser.rb, line 398 def unknown_charref(ref) end
# File lib/html/htmlparser.rb, line 394 def unknown_endtag(tag) @current = @current.parent if @current.parent end
# File lib/html/htmlparser.rb, line 401 def unknown_entityref(ref) @current.children << HTML::Text.new(@current, 0, 0, "&#{ref}<") end
# File lib/html/htmlparser.rb, line 384 def unknown_starttag(tag, attrs) attrs = attrs.inject({}) do |hash, attr| hash[attr[0].downcase] = attr[1] hash end element = HTML::Tag.new(@current || @document, 0, 0, tag.downcase, attrs, true) @current.children << element @current = element end
Generated with the Darkfish Rdoc Generator 2.