Class: HTML5::XHTMLParser

Inherits:
XMLParser show all
Defined in:
lib/html5/liberalxmlparser.rb

Overview

liberal XMTHML parser

Instance Attribute Summary

Attributes inherited from HTMLParser

#errors, #first_start_tag, #inner_html, #insert_from_table, #last_phase, #phase, #phases, #secondary_phase, #tokenizer, #tree

Instance Method Summary collapse

Methods inherited from HTMLParser

#_, #_parse, parse, #parse, #parse_error, parse_fragment, #parse_fragment, #reset_insertion_mode

Constructor Details

#initialize(options = {}) ⇒ XHTMLParser

Returns a new instance of XHTMLParser.



71
72
73
74
75
# File 'lib/html5/liberalxmlparser.rb', line 71

def initialize(options = {})
  super options
  @phases[:initial] = InitialPhase.new(self, @tree)
  @phases[:beforeHtml] = XhmlRootPhase.new(self, @tree)
end

Instance Method Details

#normalize_token(token) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
# File 'lib/html5/liberalxmlparser.rb', line 77

def normalize_token(token)
  super(token)

  # ensure that non-void XHTML elements have content so that separate
  # open and close tags are emitted
  if token[:type]  == :EndTag
    if VOID_ELEMENTS.include? token[:name]
      if @tree.open_elements[-1].name != token["name"]
        token[:type] = :EmptyTag
        token["data"] ||= {}
      end
    else
      if token[:name] == @tree.open_elements[-1].name and \
        not @tree.open_elements[-1].hasContent
        @tree.insertText('') unless
          @tree.open_elements.any? {|e|
            e.attributes.keys.include? 'xmlns' and
            e.attributes['xmlns'] != 'http://www.w3.org/1999/xhtml'
          }
       end
    end
  end

  return token
end