Class: Gammo::Parser::InTable

Inherits:
InsertionMode show all
Defined in:
lib/gammo/parser/insertion_mode/in_table.rb

Overview

Section 12.2.6.4.9.

Instance Attribute Summary

Attributes inherited from InsertionMode

#parser

Instance Method Summary collapse

Methods inherited from InsertionMode

#initialize, #process

Constructor Details

This class inherits a constructor from Gammo::Parser::InsertionMode

Instance Method Details

#character_token(token) ⇒ Object



5
6
7
8
9
10
11
12
13
14
# File 'lib/gammo/parser/insertion_mode/in_table.rb', line 5

def character_token(token)
  token.data = token.data.gsub("\x00", "")
  case parser.open_elements.last.tag
  when Tags::Table, Tags::Tbody, Tags::Tfoot, Tags::Thead, Tags::Tr
    if token.data.strip == ""
      parser.add_text token.data
      halt true
    end
  end
end

#comment_token(token) ⇒ Object



92
93
94
95
# File 'lib/gammo/parser/insertion_mode/in_table.rb', line 92

def comment_token(token)
  parser.add_child(Node::Comment.new(data: token.data))
  halt true
end

#default(_) ⇒ Object



106
107
108
109
110
111
# File 'lib/gammo/parser/insertion_mode/in_table.rb', line 106

def default(_)
  parser.foster_parenting = true
  result = InBody.new(parser).process
  parser.foster_parenting = false
  halt result
end

#doctype_token(token) ⇒ Object



97
98
99
100
# File 'lib/gammo/parser/insertion_mode/in_table.rb', line 97

def doctype_token(token)
  # Ignore the token
  halt true
end

#end_tag_token(token) ⇒ Object



77
78
79
80
81
82
83
84
85
86
87
88
89
90
# File 'lib/gammo/parser/insertion_mode/in_table.rb', line 77

def end_tag_token(token)
  case token.tag
  when Tags::Table
    parser.reset_insertion_mode if parser.pop_until(TABLE_SCOPE, Tags::Table)
    # Ignore the token
    halt true
  when Tags::Body, Tags::Caption, Tags::Col, Tags::Colgroup, Tags::Html,
    Tags::Tbody, Tags::Td, Tags::Tfoot, Tags::Th, Tags::Thead, Tags::Tr
    # Ignore the token
    halt true
  when Tags::Template
    halt InHead.new(parser).process
  end
end

#error_token(token) ⇒ Object



102
103
104
# File 'lib/gammo/parser/insertion_mode/in_table.rb', line 102

def error_token(token)
  InBody.new(parser).process
end

#start_tag_token(token) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/gammo/parser/insertion_mode/in_table.rb', line 16

def start_tag_token(token)
  case token.tag
  when Tags::Caption
    parser.clear_stack_to_context(TABLE_SCOPE)
    parser.active_formatting_elements << Node::DEFAULT_SCOPE_MARKER
    parser.add_element
    parser.insertion_mode = InCaption
    halt true
  when Tags::Colgroup
    parser.clear_stack_to_context(TABLE_SCOPE)
    parser.add_element
    parser.insertion_mode = InColumnGroup
    halt true
  when Tags::Col
    parser.parse_implied_token(Tokenizer::StartTagToken, Tags::Colgroup, Tags::Colgroup.to_s)
    halt false
  when Tags::Tbody, Tags::Tfoot, Tags::Thead
    parser.clear_stack_to_context(TABLE_SCOPE)
    parser.add_element
    parser.insertion_mode = InTableBody
    halt true
  when Tags::Td, Tags::Th, Tags::Tr
    parser.parse_implied_token(Tokenizer::StartTagToken, Tags::Tbody, Tags::Tbody.to_s)
    halt false
  when Tags::Table
    if parser.pop_until(TABLE_SCOPE, Tags::Table)
      parser.reset_insertion_mode
      halt false
    end
    # ignore the token
    halt true
  when Tags::Style, Tags::Script, Tags::Template
    halt InHead.new(parser).process
  when Tags::Input
    token.attributes.each do |attr|
      # skip setting frameset_ok = false
      if attr.key == 'type' && attr.value.downcase == 'hidden'
        parser.add_element
        parser.open_elements.pop
        halt true
      end
    end
  when Tags::Form
    # ignore the token
    halt true if parser.form || parser.open_elements.any? { |open_element| open_element.tag == Tags::Template }
    parser.add_element
    parser.form = parser.open_elements.pop
  when Tags::Select
    parser.reconstruct_active_formatting_elements
    case parser.top.tag
    when Tags::Table, Tags::Tbody, Tags::Tfoot, Tags::Thead, Tags::Tr
      parser.foster_parenting = true
    end
    parser.add_element
    parser.foster_parenting = false
    parser.frameset_ok = true
    parser.insertion_mode = InSelectInTable
    halt true
  end
end