Class: HTMLTree::Parser

Inherits:
HTML::StackingParser show all
Defined in:
lib/web/htmltools/tree.rb

Overview

:nodoc: all

Constant Summary

Constants inherited from SGMLParser

SGMLParser::Attrfind, SGMLParser::Charref, SGMLParser::Commentclose, SGMLParser::Commentopen, SGMLParser::Endbracket, SGMLParser::Endtagopen, SGMLParser::Entitydefs, SGMLParser::Entityref, SGMLParser::Incomplete, SGMLParser::Interesting, SGMLParser::Special, SGMLParser::Starttagopen, SGMLParser::Tagfind

Instance Method Summary collapse

Methods inherited from HTML::StackingParser

#feed, #last_tag, #parent_tag, #parse_file_named, #stack, #strip_whitespace=

Methods inherited from SGMLParser

#close, #feed, #finish_endtag, #finish_starttag, #goahead, #handle_charref, #handle_data, #handle_endtag, #handle_entityref, #handle_starttag, #has_context, #parse_comment, #parse_endtag, #parse_special, #parse_starttag, #report_unbalanced, #setliteral, #setnomoretags, #unknown_charref, #unknown_endtag, #unknown_entityref, #unknown_starttag

Constructor Details

#initialize(verbose = false, strip_white = true) ⇒ Parser

verbose

if true, will warn to $stderr on unknown

tags/entities/characters, as well as missing end tags and extra end tags.

strip_white

if true, remove all non-essential whitespace. Note

that there are browser bugs that may cause this to change the appearance of HTML (even though it shouldn’t by the standard).



29
30
31
32
# File 'lib/web/htmltools/tree.rb', line 29

def initialize(verbose=false, strip_white=true)
  super
  reset
end

Instance Method Details

#htmlObject

Return the <html> node, if any.



47
48
49
# File 'lib/web/htmltools/tree.rb', line 47

def html
  @rootNode.html_node()
end

#resetObject

Reset this parser so that it can parse a new document.



35
36
37
38
# File 'lib/web/htmltools/tree.rb', line 35

def reset
  super
  @rootNode = @currentNode = Document.new
end

#treeObject

Return the tree that was built. This will be an HTMLTree::Element that represents the whole document. The <html> node is a child of this.



42
43
44
# File 'lib/web/htmltools/tree.rb', line 42

def tree
  @rootNode
end