+ # 8.2.5.4.9 http://www.w3.org/TR/html5/syntax.html#parsing-main-intable
+ ins_mode_in_table_else = (t) ->
+ parse_error()
+ flag_foster_parenting = true
+ ins_mode_in_body t
+ flag_foster_parenting = false
+ return
+ can_in_table = { # FIXME do this inline like everywhere else
+ 'table': true
+ 'tbody': true
+ 'tfoot': true
+ 'thead': true
+ 'tr': true
+ }
+ ins_mode_in_table = (t) ->
+ switch t.type
+ when TYPE_TEXT
+ if can_in_table[t.name]
+ original_ins_mode = ins_mode
+ ins_mode = ins_mode_in_table_text
+ process_token t
+ else
+ ins_mode_in_table_else t
+ when TYPE_COMMENT
+ insert_comment t
+ when TYPE_DOCTYPE
+ parse_error()
+ when TYPE_START_TAG
+ switch t.name
+ when 'caption'
+ clear_stack_to_table_context()
+ afe_push_marker()
+ insert_html_element t
+ ins_mode = ins_mode_in_caption
+ when 'colgroup'
+ clear_stack_to_table_context()
+ insert_html_element t
+ ins_mode = ins_mode_in_column_group
+ when 'col'
+ clear_stack_to_table_context()
+ insert_html_element new_open_tag 'colgroup'
+ ins_mode = ins_mode_in_column_group
+ process_token t
+ when 'tbody', 'tfoot', 'thead'
+ clear_stack_to_table_context()
+ insert_html_element t
+ ins_mode = ins_mode_in_table_body
+ when 'td', 'th', 'tr'
+ clear_stack_to_table_context()
+ insert_html_element new_open_tag 'tbody'
+ ins_mode = ins_mode_in_table_body
+ process_token t
+ when 'table'
+ parse_error()
+ if is_in_table_scope 'table'
+ loop
+ el = open_els.shift()
+ if el.name is 'table'
+ break
+ reset_ins_mode()
+ process_token t
+ when 'style', 'script', 'template'
+ ins_mode_in_head t
+ when 'input'
+ unless is_input_hidden_tok t
+ ins_mode_in_table_else t
+ else
+ parse_error()
+ el = insert_html_element t
+ open_els.shift()
+ t.acknowledge_self_closing()
+ when 'form'
+ parse_error()
+ if form_element_pointer?
+ return
+ if template_tag_is_open()
+ return
+ form_element_pointer = insert_html_element t
+ open_els.shift()
+ else
+ ins_mode_in_table_else t
+ when TYPE_END_TAG
+ switch t.name
+ when 'table'
+ if is_in_table_scope 'table'
+ loop
+ el = open_els.shift()
+ if el.name is 'table'
+ break
+ reset_ins_mode()
+ else
+ parse_error
+ when 'body', 'caption', 'col', 'colgroup', 'html', 'tbody', 'td', 'tfoot', 'th', 'thead', 'tr'
+ parse_error()
+ when 'template'
+ ins_mode_in_head t
+ else
+ ins_mode_in_table_else t
+ when TYPE_EOF
+ ins_mode_in_body t
+ else
+ ins_mode_in_table_else t
+
+
+ # 8.2.5.4.10 http://www.w3.org/TR/html5/syntax.html#parsing-main-intabletext
+ ins_mode_in_table_text = (t) ->
+ if t.type is TYPE_TEXT and t.text is "\u0000"
+ # huh? I thought the tokenizer didn't emit these
+ parse_error()
+ return
+ if t.type is TYPE_TEXT
+ pending_table_character_tokens.push t
+ return
+ # Anything else
+ all_space = true
+ for old in pending_table_character_tokens
+ unless is_space_tok old
+ all_space = false
+ break
+ if all_space
+ for old in pending_table_character_tokens
+ insert_character old
+ else
+ for old in pending_table_character_tokens
+ ins_mode_table_else old
+ pending_table_character_tokens = [] # FIXME test (spec doesn't say this)
+ ins_mode = original_ins_mode
+ process_token t
+
+ # 8.2.5.4.11 http://www.w3.org/TR/html5/syntax.html#parsing-main-incaption
+ ins_mode_in_caption = (t) ->
+ if t.type is TYPE_END_TAG and t.name is 'caption'
+ if is_in_table_scope 'caption'
+ generate_implied_end_tags()
+ if open_els[0].name isnt 'caption'
+ parse_error()
+ loop
+ el = open_els.shift()
+ if el.name is 'caption'
+ break
+ clear_afe_to_marker()
+ ins_mode = ins_mode_in_table
+ else
+ parse_error()
+ # fragment case
+ return
+ if (t.type is TYPE_START_TAG and (t.name is 'caption' or t.name is 'col' or t.name is 'colgroup' or t.name is 'tbody' or t.name is 'td' or t.name is 'tfoot' or t.name is 'th' or t.name is 'thead' or t.name is 'tr')) or t.type is TYPE_END_TAG and t.name is 'table'
+ parse_error()
+ if is_in_table_scope 'caption'
+ loop
+ el = open_els.shift()
+ if el.name is 'caption'
+ break
+ clear_afe_to_marker()
+ ins_mode = ins_mode_in_table
+ process_token t
+ # else fragment case
+ return
+ if t.type is TYPE_END_TAG and (t.name is 'body' or t.name is 'col' or t.name is 'colgroup' or t.name is 'html' or t.name is 'tbody' or t.name is 'td' or t.name is 'tfoot' or t.name is 'th' or t.name is 'thead' or t.name is 'tr')
+ parse_error()
+ return
+ # Anything else
+ ins_mode_in_body t
+
+ # 8.2.5.4.12 http://www.w3.org/TR/html5/syntax.html#parsing-main-incolgroup
+ ins_mode_in_column_group = (t) ->
+ if is_space_tok t
+ insert_character t
+ return
+ if t.type is TYPE_COMMENT
+ insert_comment t
+ return
+ if t.type is TYPE_DOCTYPE
+ parse_error()
+ return
+ if t.type is TYPE_START_TAG and t.name is 'html'
+ ins_mode_in_body t
+ return
+ if t.type is TYPE_START_TAG and t.name is 'col'
+ el = insert_html_element t
+ open_els.shift()
+ t.acknowledge_self_closing()
+ return
+ if t.type is TYPE_END_TAG and t.name is 'colgroup'
+ if open_els[0].name is 'colgroup'
+ open_els.shift()
+ ins_mode = ins_mode_in_table
+ else
+ parse_error()
+ return
+ if t.type is TYPE_END_TAG and t.name is 'col'
+ parse_error()
+ return
+ if (t.type is TYPE_START_TAG or t.type is TYPE_END_TAG) and t.name is 'template'
+ ins_mode_in_head t
+ return
+ if t.type is TYPE_EOF
+ ins_mode_in_body t
+ return
+ # Anything else
+ if open_els[0].name isnt 'colgroup'
+ parse_error()
+ return
+ open_els.shift()
+ ins_mode = ins_mode_in_table
+ process_token t
+ return
+
+ # 8.2.5.4.13 http://www.w3.org/TR/html5/syntax.html#parsing-main-intbody
+ ins_mode_in_table_body = (t) ->
+ if t.type is TYPE_START_TAG and t.name is 'tr'
+ clear_stack_to_table_body_context()
+ insert_html_element t
+ ins_mode = ins_mode_in_row
+ return
+ if t.type is TYPE_START_TAG and (t.name is 'th' or t.name is 'td')
+ parse_error()
+ clear_stack_to_table_body_context()
+ insert_html_element new_open_tag 'tr'
+ ins_mode = ins_mode_in_row
+ process_token t
+ return
+ if t.type is TYPE_END_TAG and (t.name is 'tbody' or t.name is 'tfoot' or t.name is 'thead')
+ unless is_in_table_scope t.name # fixfull check namespace
+ parse_error()
+ return
+ clear_stack_to_table_body_context()
+ open_els.shift()
+ ins_mode = ins_mode_in_table
+ return
+ if (t.type is TYPE_START_TAG and (t.name is 'caption' or t.name is 'col' or t.name is 'colgroup' or t.name is 'tbody' or t.name is 'tfoot' or t.name is 'thead')) or (t.type is TYPE_END_TAG and t.name is 'table')
+ has = false
+ for el in open_els
+ if el.name is 'tbody' or el.name is 'tfoot' or el.name is 'thead'
+ has = true
+ break
+ if table_scopers[el.name]
+ break
+ if !has
+ parse_error()
+ return
+ clear_stack_to_table_body_context()
+ open_els.shift()
+ ins_mode = ins_mode_in_table
+ process_token t
+ return
+ if t.type is TYPE_END_TAG and (t.name is 'body' or t.name is 'caption' or t.name is 'col' or t.name is 'colgroup' or t.name is 'html' or t.name is 'td' or t.name is 'th' or t.name is 'tr')
+ parse_error()
+ return
+ # Anything else
+ ins_mode_in_table t
+
+ # 8.2.5.4.14 http://www.w3.org/TR/html5/syntax.html#parsing-main-intr
+ ins_mode_in_row = (t) ->
+ if t.type is TYPE_START_TAG and (t.name is 'th' or t.name is 'td')
+ clear_stack_to_table_row_context()
+ insert_html_element t
+ ins_mode = ins_mode_in_cell
+ afe_push_marker()
+ return
+ if t.type is TYPE_END_TAG and t.name is 'tr'
+ if is_in_table_scope 'tr'
+ clear_stack_to_table_row_context()
+ open_els.shift()
+ ins_mode = ins_mode_in_table_body
+ else
+ parse_error()
+ return
+ if (t.type is TYPE_START_TAG and (t.name is 'caption' or t.name is 'col' or t.name is 'colgroup' or t.name is 'tbody' or t.name is 'tfoot' or t.name is 'thead' or t.name is 'tr')) or t.type is TYPE_END_TAG and t.name is 'table'
+ if is_in_table_scope 'tr'
+ clear_stack_to_table_row_context()
+ open_els.shift()
+ ins_mode = ins_mode_in_table_body
+ process_token t
+ else
+ parse_error()
+ return
+ if t.type is TYPE_END_TAG and (t.name is 'tbody' or t.name is 'tfoot' or t.name is 'thead')
+ if is_in_table_scope t.name # fixfull namespace
+ if is_in_table_scope 'tr'
+ clear_stack_to_table_row_context()
+ open_els.shift()
+ ins_mode = ins_mode_in_table_body
+ process_token t
+ else
+ parse_error()
+ return
+ if t.type is TYPE_END_TAG and (t.name is 'body' or t.name is 'caption' or t.name is 'col' or t.name is 'colgroup' or t.name is 'html' or t.name is 'td' or t.name is 'th')
+ parse_error()
+ return
+ # Anything else
+ ins_mode_in_table t
+
+ # http://www.w3.org/TR/html5/syntax.html#close-the-cell
+ close_the_cell = ->
+ generate_implied_end_tags()
+ unless open_els[0].name is 'td' or open_els[0] is 'th'
+ parse_error()
+ loop
+ el = open_els.shift()
+ if el.name is 'td' or el.name is 'th'
+ break
+ clear_afe_to_marker()
+ ins_mode = ins_mode_in_row
+
+ # 8.2.5.4.15 http://www.w3.org/TR/html5/syntax.html#parsing-main-intd
+ ins_mode_in_cell = (t) ->
+ if t.type is TYPE_END_TAG and (t.name is 'td' or t.name is 'th')
+ if is_in_table_scope t.name
+ generate_implied_end_tags()
+ if open_els[0].name isnt t.name
+ parse_error
+ loop
+ el = open_els.shift()
+ if el.name is t.name
+ break
+ clear_afe_to_marker()
+ ins_mode = ins_mode_in_row
+ else
+ parse_error()
+ return
+ if t.type is TYPE_START_TAG and (t.name is 'caption' or t.name is 'col' or t.name is 'colgroup' or t.name is 'tbody' or t.name is 'td' or t.name is 'tfoot' or t.name is 'th' or t.name is 'thead' or t.name is 'tr')
+ has = false
+ for el in open_els
+ if el.name is 'td' or el.name is 'th'
+ has = true
+ break
+ if table_scopers[el.name]
+ break
+ if !has
+ parse_error()
+ return
+ close_the_cell()
+ process_token t
+ return
+ if t.type is TYPE_END_TAG and (t.name is 'body' or t.name is 'caption' or t.name is 'col' or t.name is 'colgroup' or t.name is 'html')
+ parse_error()
+ return
+ if t.type is TYPE_END_TAG and (t.name is 'table' or t.name is 'tbody' or t.name is 'tfoot' or t.name is 'thead' or t.name is 'tr')
+ if is_in_table_scope t.name # fixfull namespace
+ close_the_cell()
+ process_token t
+ else
+ parse_error()
+ return
+ # Anything Else
+ ins_mode_in_body t
+
+ # 8.2.5.4.16 http://www.w3.org/TR/html5/syntax.html#parsing-main-inselect
+ ins_mode_in_select = (t) ->
+ if t.type is TYPE_TEXT and t.text is "\u0000"
+ parse_error()
+ return
+ if t.type is TYPE_TEXT
+ insert_character t
+ return
+ if t.type is TYPE_COMMENT
+ insert_comment t
+ return
+ if t.type is TYPE_DOCTYPE
+ parse_error()
+ return
+ if t.type is TYPE_START_TAG and t.name is 'html'
+ ins_mode_in_body t
+ return
+ if t.type is TYPE_START_TAG and t.name is 'option'
+ if open_els[0].name is 'option'
+ open_els.shift()
+ insert_html_element t
+ return
+ if t.type is TYPE_START_TAG and t.name is 'optgroup'
+ if open_els[0].name is 'option'
+ open_els.shift()
+ if open_els[0].name is 'optgroup'
+ open_els.shift()
+ insert_html_element t
+ return
+ if t.type is TYPE_END_TAG and t.name is 'optgroup'
+ if open_els[0].name is 'option' and open_els[1].name is 'optgroup'
+ open_els.shift()
+ if open_els[0].name is 'optgroup'
+ open_els.shift()
+ else
+ parse_error()
+ return
+ if t.type is TYPE_END_TAG and t.name is 'option'
+ if open_els[0].name is 'option'
+ open_els.shift()
+ else
+ parse_error()
+ return
+ if t.type is TYPE_END_TAG and t.name is 'select'
+ if is_in_select_scope 'select'
+ loop
+ el = open_els.shift()
+ if el.name is 'select'
+ break
+ reset_ins_mode()
+ else
+ parse_error()
+ return
+ if t.type is TYPE_START_TAG and t.name is 'select'
+ parse_error()
+ loop
+ el = open_els.shift()
+ if el.name is 'select'
+ break
+ reset_ins_mode()
+ # spec says that this is the same as </select> but it doesn't say
+ # to check scope first
+ return
+ if t.type is TYPE_START_TAG and (t.name is 'input' or t.name is 'keygen' or t.name is 'textarea')
+ parse_error()
+ if is_in_select_scope 'select'
+ return
+ loop
+ el = open_els.shift()
+ if el.name is 'select'
+ break
+ reset_ins_mode()
+ process_token t
+ return
+ if t.type is TYPE_START_TAG and (t.name is 'script' or t.name is 'template')
+ ins_mode_in_head t
+ return
+ if t.type is TYPE_EOF
+ ins_mode_in_body t
+ return
+ # Anything else
+ parse_error()
+ return
+
+ # 8.2.5.4.17 http://www.w3.org/TR/html5/syntax.html#parsing-main-inselectintable
+ ins_mode_in_select_in_table = (t) ->
+ if t.type is TYPE_START_TAG and (t.name is 'caption' or t.name is 'table' or t.name is 'tbody' or t.name is 'tfoot' or t.name is 'thead' or t.name is 'tr' or t.name is 'td' or t.name is 'th')
+ parse_error()
+ loop
+ el = open_els.shift()
+ if el.name is 'select'
+ break
+ reset_ins_mode()
+ process_token t
+ return
+ if t.type is TYPE_END_TAG and (t.name is 'caption' or t.name is 'table' or t.name is 'tbody' or t.name is 'tfoot' or t.name is 'thead' or t.name is 'tr' or t.name is 'td' or t.name is 'th')
+ parse_error()
+ unless is_in_table_scope t.name, NS_HTML
+ return
+ loop
+ el = open_els.shift()
+ if el.name is 'select'
+ break
+ reset_ins_mode()
+ process_token t
+ return
+ # Anything else
+ ins_mode_in_select t
+ return
+
+ # 8.2.5.4.18 http://www.w3.org/TR/html5/syntax.html#parsing-main-intemplate
+ ins_mode_in_template = (t) ->
+ if t.type is TYPE_TEXT or t.type is TYPE_COMMENT or t.type is TYPE_DOCTYPE
+ ins_mode_in_body t
+ return
+ if (t.type is TYPE_START_TAG and (t.name is 'base' or t.name is 'basefont' or t.name is 'bgsound' or t.name is 'link' or t.name is 'meta' or t.name is 'noframes' or t.name is 'script' or t.name is 'style' or t.name is 'template' or t.name is 'title')) or (t.type is TYPE_END_TAG and t.name is 'template')
+ ins_mode_in_head t
+ return
+ if t.type is TYPE_START_TAG and (t.name is 'caption' or t.name is 'colgroup' or t.name is 'tbody' or t.name is 'tfoot' or t.name is 'thead')
+ template_ins_modes.shift()
+ template_ins_modes.unshift ins_mode_in_table
+ ins_mode = ins_mode_in_table
+ process_token t
+ return
+ if t.type is TYPE_START_TAG and t.name is 'col'
+ template_ins_modes.shift()
+ template_ins_modes.unshift ins_mode_in_column_group
+ ins_mode = ins_mode_in_column_group
+ process_token t
+ return
+ if t.type is TYPE_START_TAG and t.name is 'tr'
+ template_ins_modes.shift()
+ template_ins_modes.unshift ins_mode_in_table_body
+ ins_mode = ins_mode_in_table_body
+ process_token t
+ return
+ if t.type is TYPE_START_TAG and (t.name is 'td' or t.name is 'th')
+ template_ins_modes.shift()
+ template_ins_modes.unshift ins_mode_in_row
+ ins_mode = ins_mode_in_row
+ process_token t
+ return
+ if t.type is TYPE_START_TAG
+ template_ins_modes.shift()
+ template_ins_modes.unshift ins_mode_in_body
+ ins_mode = ins_mode_in_body
+ process_token t
+ return
+ if t.type is TYPE_END_TAG
+ parse_error()
+ return
+ if t.type is TYPE_EOF
+ unless template_tag_is_open()
+ stop_parsing()
+ return
+ parse_error()
+ loop
+ el = open_els.shift()
+ if el.name is 'template' # fixfull check namespace
+ break
+ clear_afe_to_marker()
+ template_ins_modes.shift()
+ reset_ins_mode()
+ process_token t
+
+ # 8.2.5.4.19 http://www.w3.org/TR/html5/syntax.html#parsing-main-afterbody
+ ins_mode_after_body = (t) ->
+ if is_space_tok t
+ ins_mode_in_body t
+ return
+ if t.type is TYPE_COMMENT
+ insert_comment t, [open_els[0], open_els[0].children.length]
+ return
+ if t.type is TYPE_DOCTYPE
+ parse_error()
+ return
+ if t.type is TYPE_START_TAG and t.name is 'html'
+ ins_mode_in_body t
+ return
+ if t.type is TYPE_END_TAG and t.name is 'html'
+ # fixfull fragment case
+ ins_mode = ins_mode_after_after_body
+ return
+ if t.type is TYPE_EOF
+ stop_parsing()
+ return
+ # Anything ELse
+ parse_error()
+ ins_mode = ins_mode_in_body
+ process_token t
+
+ # 8.2.5.4.20 http://www.w3.org/TR/html5/syntax.html#parsing-main-inframeset
+ ins_mode_in_frameset = (t) ->
+ if is_space_tok t
+ insert_character t
+ return
+ if t.type is TYPE_COMMENT
+ insert_comment t
+ return
+ if t.type is TYPE_DOCTYPE
+ parse_error()
+ return
+ if t.type is TYPE_START_TAG and t.name is 'html'
+ ins_mode_in_body t
+ return
+ if t.type is TYPE_START_TAG and t.name is 'frameset'
+ insert_html_element t
+ return
+ if t.type is TYPE_END_TAG and t.name is 'frameset'
+ # TODO ?correct for: "if the current node is the root html element"
+ if open_els.length is 1
+ parse_error()
+ return # fragment case
+ open_els.shift()
+ if flag_fragment_parsing is false and open_els[0].name isnt 'frameset'
+ ins_mode = ins_mode_after_frameset
+ return
+ if t.type is TYPE_START_TAG and t.name is 'frame'
+ insert_html_element t
+ open_els.shift()
+ t.acknowledge_self_closing()
+ return
+ if t.type is TYPE_START_TAG and t.name is 'noframes'
+ ins_mode_in_head t
+ return
+ if t.type is TYPE_EOF
+ # TODO ?correct for: "if the current node is not the root html element"
+ if open_els.length isnt 1
+ parse_error()
+ stop_parsing()
+ return
+ # Anything else
+ parse_error()
+ return
+
+ # 8.2.5.4.21 http://www.w3.org/TR/html5/syntax.html#parsing-main-afterframeset
+ ins_mode_after_frameset = (t) ->
+ if is_space_tok t
+ insert_character t
+ return
+ if t.type is TYPE_COMMENT
+ insert_comment t
+ return
+ if t.type is TYPE_DOCTYPE
+ parse_error()
+ return
+ if t.type is TYPE_START_TAG and t.name is 'html'
+ ins_mode_in_body t
+ return
+ if t.type is TYPE_END_TAG and t.name is 'html'
+ insert_mode = ins_mode_after_after_frameset
+ return
+ if t.type is TYPE_START_TAG and t.name is 'noframes'
+ ins_mode_in_head t
+ return
+ if t.type is TYPE_EOF
+ stop_parsing()
+ return
+ # Anything else
+ parse_error()
+ return
+
+ # 8.2.5.4.22 http://www.w3.org/TR/html5/syntax.html#the-after-after-body-insertion-mode
+ ins_mode_after_after_body = (t) ->
+ if t.type is TYPE_COMMENT
+ insert_comment t, [doc, doc.children.length]
+ return
+ if t.type is TYPE_DOCTYPE or is_space_tok(t) or (t.type is TYPE_START_TAG and t.name is 'html')
+ ins_mode_in_body t
+ return
+ if t.type is TYPE_EOF
+ stop_parsing()
+ return
+ # Anything else
+ parse_error()
+ ins_mode = ins_mode_in_body
+ return
+
+ # 8.2.5.4.23 http://www.w3.org/TR/html5/syntax.html#the-after-after-frameset-insertion-mode
+ ins_mode_after_after_frameset = (t) ->
+ if t.type is TYPE_COMMENT
+ insert_comment t, [doc, doc.children.length]
+ return
+ if t.type is TYPE_DOCTYPE or is_space_tok(t) or (t.type is TYPE_START_TAG and t.name is 'html')
+ ins_mode_in_body t
+ return
+ if t.type is TYPE_EOF
+ stop_parsing()
+ return
+ if t.type is TYPE_START_TAG and t.name is 'noframes'
+ ins_mode_in_head t
+ return
+ # Anything else
+ parse_error()
+ return
+
+ # 8.2.5.5 http://www.w3.org/TR/html5/syntax.html#parsing-main-inforeign
+ has_color_face_or_size = (t) ->
+ for a in t.attrs_a
+ if a[0] is 'color' or a[0] is 'face' or a[0] is 'size'
+ return true
+ return false
+ in_foreign_content_end_script = ->
+ open_els.shift()
+ # fixfull
+ return
+ in_foreign_content_other_start = (t) ->
+ acn = adjusted_current_node()
+ if acn.namespace is NS_MATHML
+ adjust_mathml_attributes t
+ if acn.namespace is NS_SVG and svg_name_fixes[t.name]?
+ t.name = svg_name_fixes[t.name]
+ if acn.namespace is NS_SVG
+ adjust_svg_attributes t
+ adjust_foreign_attributes t
+ insert_foreign_element t, acn.namespace
+ if t.flag 'self-closing'
+ if t.name is 'script'
+ t.acknowledge_self_closing()
+ in_foreign_content_end_script()
+ else
+ open_els.shift()
+ t.acknowledge_self_closing()
+ return
+ in_foreign_content = (t) ->
+ if t.type is TYPE_TEXT and t.text is "\u0000"
+ parse_error()
+ insert_character new_character_token "\ufffd"
+ return
+ if is_space_tok t
+ insert_character t
+ return
+ if t.type is TYPE_TEXT
+ flag_frameset_ok = false
+ insert_character t
+ return
+ if t.type is TYPE_COMMENT
+ insert_comment t
+ return
+ if t.type is TYPE_DOCTYPE
+ parse_error()
+ return
+ if t.type is TYPE_START_TAG and (t.name is 'b' or t.name is 'big' or t.name is 'blockquote' or t.name is 'body' or t.name is 'br' or t.name is 'center' or t.name is 'code' or t.name is 'dd' or t.name is 'div' or t.name is 'dl' or t.name is 'dt' or t.name is 'em' or t.name is 'embed' or t.name is 'h1' or t.name is 'h2' or t.name is 'h3' or t.name is 'h4' or t.name is 'h5' or t.name is 'h6' or t.name is 'head' or t.name is 'hr' or t.name is 'i' or t.name is 'img' or t.name is 'li' or t.name is 'listing' or t.name is 'main' or t.name is 'meta' or t.name is 'nobr' or t.name is 'ol' or t.name is 'p' or t.name is 'pre' or t.name is 'ruby' or t.name is 's' or t.name is 'small' or t.name is 'span' or t.name is 'strong' or t.name is 'strike' or t.name is 'sub' or t.name is 'sup' or t.name is 'table' or t.name is 'tt' or t.name is 'u' or t.name is 'ul' or t.name is 'var' or (t.name is 'font' and has_color_face_or_size(t)))
+ parse_error()
+ if flag_fragment_parsing
+ in_foreign_content_other_start t
+ return
+ loop # is this safe?
+ open_els.shift()
+ cn = open_els[0]
+ if is_mathml_text_integration_point(cn) or is_html_integration(cn) or cn.namespace is NS_HTML
+ break
+ process_token t
+ return
+ if t.type is TYPE_START_TAG
+ in_foreign_content_other_start t
+ return
+ if t.type is TYPE_END_TAG and t.name is 'script' and open_els[0].name is 'script' and open_els[0].namespace is NS_SVG
+ in_foreign_content_end_script()
+ return
+ if t.type is TYPE_END_TAG
+ if open_els[0].name.toLowerCase() isnt t.name
+ parse_error()
+ for node in open_els
+ if node is open_els[open_els.length - 1]
+ return
+ if node.name.toLowerCase() is t.name
+ loop
+ el = open_els.shift()
+ if el is node
+ return
+ if node.namespace is NS_HTML
+ break
+ ins_mode t # explicitly call HTML insertion mode
+
+
+ # 8.2.4.1 http://www.w3.org/TR/html5/syntax.html#data-state
+ tok_state_data = ->
+ switch c = txt.charAt(cur++)
+ when '&'
+ return new_text_node parse_character_reference()
+ when '<'
+ tok_state = tok_state_tag_open
+ when "\u0000"
+ parse_error()
+ return new_text_node c
+ when '' # EOF
+ return new_eof_token()
+ else
+ return new_text_node c
+ return null
+
+ # 8.2.4.2 http://www.w3.org/TR/html5/syntax.html#character-reference-in-data-state
+ # not needed: tok_state_character_reference_in_data = ->
+ # just call parse_character_reference()
+
+ # 8.2.4.3 http://www.w3.org/TR/html5/syntax.html#rcdata-state
+ tok_state_rcdata = ->
+ switch c = txt.charAt(cur++)
+ when '&'
+ return new_text_node parse_character_reference()
+ when '<'
+ tok_state = tok_state_rcdata_less_than_sign
+ when "\u0000"
+ parse_error()
+ return new_character_token "\ufffd"
+ when '' # EOF
+ return new_eof_token()
+ else
+ return new_character_token c
+ return null
+
+ # 8.2.4.4 http://www.w3.org/TR/html5/syntax.html#character-reference-in-rcdata-state
+ # not needed: tok_state_character_reference_in_rcdata = ->
+ # just call parse_character_reference()
+
+ # 8.2.4.5 http://www.w3.org/TR/html5/syntax.html#rawtext-state
+ tok_state_rawtext = ->
+ switch c = txt.charAt(cur++)
+ when '<'
+ tok_state = tok_state_rawtext_less_than_sign
+ when "\u0000"
+ parse_error()
+ return new_character_token "\ufffd"
+ when '' # EOF
+ return new_eof_token()
+ else
+ return new_character_token c
+ return null
+
+ # 8.2.4.6 http://www.w3.org/TR/html5/syntax.html#script-data-state
+ tok_state_script_data = ->