+ # 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_insertion_modes.shift()
+ template_insertion_modes.unshift ins_mode_in_table
+ insertion_mode = ins_mode_in_table
+ insertion_mode t
+ return
+ if t.type is TYPE_START_TAG and t.name is 'col'
+ template_insertion_modes.shift()
+ template_insertion_modes.unshift ins_mode_in_column_group
+ insertion_mode = ins_mode_in_column_group
+ insertion_mode t
+ return
+ if t.type is TYPE_START_TAG and t.name is 'tr'
+ template_insertion_modes.shift()
+ template_insertion_modes.unshift ins_mode_in_table_body
+ insertion_mode = ins_mode_in_table_body
+ insertion_mode t
+ return
+ if t.type is TYPE_START_TAG and (t.name is 'td' or t.name is 'th')
+ template_insertion_modes.shift()
+ template_insertion_modes.unshift ins_mode_in_row
+ insertion_mode = ins_mode_in_row
+ insertion_mode t
+ return
+ if t.type is TYPE_START_TAG
+ template_insertion_modes.shift()
+ template_insertion_modes.unshift ins_mode_in_body
+ insertion_mode = ins_mode_in_body
+ insertion_mode t
+ return
+ if t.type is TYPE_END_TAG
+ parse_error()
+ return
+ if t.type is 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_insertion_modes.shift()
+ reset_insertion_mode()
+ insertion_mode t