Class: HTML5::InForeignContentPhase

Inherits:
Phase
  • Object
show all
Defined in:
lib/html5/html5parser/in_foreign_content_phase.rb

Instance Method Summary collapse

Methods inherited from Phase

#adjust_foreign_attributes, #adjust_mathml_attributes, #assert, end_tag_handlers, handle_end, handle_start, #in_scope?, #initialize, #processComment, #processDoctype, #processEndTag, #processSpaceCharacters, #processStartTag, #process_eof, #remove_open_elements_until, #startTagHtml, start_tag_handlers, tag_handlers

Constructor Details

This class inherits a constructor from HTML5::Phase

Instance Method Details

#endTagOther(name) ⇒ Object



41
42
43
44
45
46
47
48
# File 'lib/html5/html5parser/in_foreign_content_phase.rb', line 41

def endTagOther(name)
  @parser.secondary_phase.processEndTag(name)
  if @parser.phase == @parser.phases[:inForeignContent]
    if !@tree.open_elements.any? {|e| e.namespace }
      @parser.phase = @parser.secondary_phase
    end
  end
end

#processCharacters(data) ⇒ Object



6
7
8
# File 'lib/html5/html5parser/in_foreign_content_phase.rb', line 6

def processCharacters(data)
  @tree.insertText(data)
end

#startTagOther(name, attributes, self_closing) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/html5/html5parser/in_foreign_content_phase.rb', line 10

def startTagOther(name, attributes, self_closing)
  if !%w[mglyph malignmark].include?(name) && %w[mi mo mn ms mtext].include?(@tree.open_elements.last.name) &&
     @tree.open_elements.last.namespace == :math

    @parser.secondary_phase.processStartTag(name, attributes)
    if @parser.phase == @parser.phases[:inForeignContent]
      if !@tree.open_elements.any? {|e| e.namespace }
        @parser.phase = @parser.secondary_phase
      end
    end
  elsif %w[b big blockquote body br center code dd div dl dt em embed font
      h1 h2 h3 h4 h5 h6 head hr i img li listing menu meta nobr ol p pre ruby s small
      span strong strike sub sup table tt u ul var].include?(name)

    parse_error("html-in-foreign-content", :name => name)

    until @tree.open_elements.last.namespace == nil
      @tree.open_elements.pop
    end
    @parser.phase = @parser.secondary_phase
    @parser.phase.processStartTag(name, attributes)
  else
    if @tree.open_elements.last.namespace == :math
      attribtues = adjust_mathml_attributes(attributes)
    end
    attributes = adjust_foreign_attributes(attributes)
    @tree.insert_foreign_element(name, attributes, @tree.open_elements.last.namespace)
    @tree.open_elements.pop if self_closing
  end
end