+ return tok_cur_tag
+ # fall through
+ if is_uc_alpha(c)
+ tok_cur_tag.name += c.toLowerCase()
+ temporary_buffer += c
+ return
+ if is_lc_alpha(c)
+ tok_cur_tag.name += c
+ temporary_buffer += c
+ return
+ # Anything else
+ tok_state = tok_state_script_data
+ cur -= 1 # Reconsume
+ return new_character_token "</#{temporary_buffer}" # fixfull split
+
+ # 8.2.4.20 http://www.w3.org/TR/html5/syntax.html#script-data-escape-start-state
+ tok_state_script_data_escape_start = ->
+ c = txt.charAt(cur++)
+ if c is '-'
+ tok_state = tok_state_script_data_escape_start_dash
+ return new_character_token '-'
+ # Anything else
+ tok_state = tok_state_script_data
+ cur -= 1 # Reconsume
+ return
+
+ # 8.2.4.21 http://www.w3.org/TR/html5/syntax.html#script-data-escape-start-dash-state
+ tok_state_script_data_escape_start_dash = ->
+ c = txt.charAt(cur++)
+ if c is '-'
+ tok_state = tok_state_script_data_escaped_dash_dash
+ return new_character_token '-'
+ # Anything else
+ tok_state = tok_state_script_data
+ cur -= 1 # Reconsume
+ return
+
+ # 8.2.4.22 http://www.w3.org/TR/html5/syntax.html#script-data-escaped-state
+ tok_state_script_data_escaped = ->
+ c = txt.charAt(cur++)
+ if c is '-'
+ tok_state = tok_state_script_data_escaped_dash
+ return new_character_token '-'
+ if c is '<'
+ tok_state = tok_state_script_data_escaped_less_than_sign
+ return
+ if c is "\u0000"
+ parse_error()
+ return new_character_token "\ufffd"
+ if c is '' # EOF
+ tok_state = tok_state_data
+ parse_error()
+ cur -= 1 # Reconsume
+ return
+ # Anything else
+ return new_character_token c
+
+ # 8.2.4.23 http://www.w3.org/TR/html5/syntax.html#script-data-escaped-dash-state
+ tok_state_script_data_escaped_dash = ->
+ c = txt.charAt(cur++)
+ if c is '-'
+ tok_state = tok_state_script_data_escaped_dash_dash
+ return new_character_token '-'
+ if c is '<'
+ tok_state = tok_state_script_data_escaped_less_than_sign
+ return
+ if c is "\u0000"
+ parse_error()
+ tok_state = tok_state_script_data_escaped
+ return new_character_token "\ufffd"
+ if c is '' # EOF
+ tok_state = tok_state_data
+ parse_error()
+ cur -= 1 # Reconsume
+ return
+ # Anything else
+ tok_state = tok_state_script_data_escaped
+ return new_character_token c
+
+ # 8.2.4.24 http://www.w3.org/TR/html5/syntax.html#script-data-escaped-dash-dash-state
+ tok_state_script_data_escaped_dash_dash = ->
+ c = txt.charAt(cur++)
+ if c is '-'
+ return new_character_token '-'
+ if c is '<'
+ tok_state = tok_state_script_data_escaped_less_than_sign
+ return
+ if c is '>'
+ tok_state = tok_state_script_data
+ return new_character_token '>'
+ if c is "\u0000"
+ parse_error()
+ tok_state = tok_state_script_data_escaped
+ return new_character_token "\ufffd"
+ if c is '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # Reconsume
+ return
+ # Anything else
+ tok_state = tok_state_script_data_escaped
+ return new_character_token c
+
+ # 8.2.4.25 http://www.w3.org/TR/html5/syntax.html#script-data-escaped-less-than-sign-state
+ tok_state_script_data_escaped_less_than_sign = ->
+ c = txt.charAt(cur++)
+ if c is '/'
+ temporary_buffer = ''
+ tok_state = tok_state_script_data_escaped_end_tag_open
+ return
+ if is_uc_alpha(c)
+ temporary_buffer = c.toLowerCase() # yes, really
+ tok_state = tok_state_script_data_double_escape_start
+ return new_character_token "<#{c}" # fixfull split
+ if is_lc_alpha(c)
+ temporary_buffer = c
+ tok_state = tok_state_script_data_double_escape_start
+ return new_character_token "<#{c}" # fixfull split
+ # Anything else
+ tok_state = tok_state_script_data_escaped
+ cur -= 1 # Reconsume
+ return new_character_token '<'
+
+ # 8.2.4.26 http://www.w3.org/TR/html5/syntax.html#script-data-escaped-end-tag-open-state
+ tok_state_script_data_escaped_end_tag_open = ->
+ c = txt.charAt(cur++)
+ if is_uc_alpha(c)
+ tok_cur_tag = new_end_tag c.toLowerCase()
+ temporary_buffer += c
+ tok_state = tok_state_script_data_escaped_end_tag_name
+ return
+ if is_lc_alpha(c)
+ tok_cur_tag = new_end_tag c
+ temporary_buffer += c
+ tok_state = tok_state_script_data_escaped_end_tag_name
+ return
+ # Anything else
+ tok_state = tok_state_script_data_escaped
+ cur -= 1 # Reconsume
+ return new_character_token '</' # fixfull split
+
+ # 8.2.4.27 http://www.w3.org/TR/html5/syntax.html#script-data-escaped-end-tag-name-state
+ tok_state_script_data_escaped_end_tag_name = ->
+ c = txt.charAt(cur++)
+ if c is "\t" or c is "\u000a" or c is "\u000c" or c is ' '
+ if is_appropriate_end_tag tok_cur_tag
+ tok_state = tok_state_before_attribute_name
+ return
+ # fall through
+ if c is '/'
+ if is_appropriate_end_tag tok_cur_tag
+ tok_state = tok_state_self_closing_start_tag
+ return
+ # fall through
+ if c is '>'
+ if is_appropriate_end_tag tok_cur_tag
+ tok_state = tok_state_data
+ return tok_cur_tag
+ # fall through
+ if is_uc_alpha(c)
+ tok_cur_tag.name += c.toLowerCase()
+ temporary_buffer += c.toLowerCase()
+ return
+ if is_lc_alpha(c)
+ tok_cur_tag.name += c
+ temporary_buffer += c.toLowerCase()
+ return
+ # Anything else
+ tok_state = tok_state_script_data_escaped
+ cur -= 1 # Reconsume
+ return new_character_token "</#{temporary_buffer}" # fixfull split
+
+ # 8.2.4.28 http://www.w3.org/TR/html5/syntax.html#script-data-double-escape-start-state
+ tok_state_script_data_double_escape_start = ->
+ c = txt.charAt(cur++)
+ if c is "\t" or c is "\u000a" or c is "\u000c" or c is ' ' or c is '/' or c is '>'
+ if temporary_buffer is 'script'
+ tok_state = tok_state_script_data_double_escaped
+ else
+ tok_state = tok_state_script_data_escaped
+ return new_character_token c
+ if is_uc_alpha(c)
+ temporary_buffer += c.toLowerCase() # yes, really lowercase
+ return new_character_token c
+ if is_lc_alpha(c)
+ temporary_buffer += c
+ return new_character_token c
+ # Anything else
+ tok_state = tok_state_script_data_escaped
+ cur -= 1 # Reconsume
+ return
+
+ # 8.2.4.29 http://www.w3.org/TR/html5/syntax.html#script-data-double-escaped-state
+ tok_state_script_data_double_escaped = ->
+ c = txt.charAt(cur++)
+ if c is '-'
+ tok_state = tok_state_script_data_double_escaped_dash
+ return new_character_token '-'
+ if c is '<'
+ tok_state = tok_state_script_data_double_escaped_less_than_sign
+ return new_character_token '<'
+ if c is "\u0000"
+ parse_error()
+ return new_character_token "\ufffd"
+ if c is '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # Reconsume
+ return
+ # Anything else
+ return new_character_token c
+
+ # 8.2.4.30 http://www.w3.org/TR/html5/syntax.html#script-data-double-escaped-dash-state
+ tok_state_script_data_double_escaped_dash = ->
+ c = txt.charAt(cur++)
+ if c is '-'
+ tok_state = tok_state_script_data_double_escaped_dash_dash
+ return new_character_token '-'
+ if c is '<'
+ tok_state = tok_state_script_data_double_escaped_less_than_sign
+ return new_character_token '<'
+ if c is "\u0000"
+ parse_error()
+ tok_state = tok_state_script_data_double_escaped
+ return new_character_token "\ufffd"
+ if c is '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # Reconsume
+ return
+ # Anything else
+ tok_state = tok_state_script_data_double_escaped
+ return new_character_token c
+
+ # 8.2.4.31 http://www.w3.org/TR/html5/syntax.html#script-data-double-escaped-dash-dash-state
+ tok_state_script_data_double_escaped_dash_dash = ->
+ c = txt.charAt(cur++)
+ if c is '-'
+ return new_character_token '-'
+ if c is '<'
+ tok_state = tok_state_script_data_double_escaped_less_than_sign
+ return new_character_token '<'
+ if c is '>'
+ tok_state = tok_state_script_data
+ return new_character_token '>'
+ if c is "\u0000"
+ parse_error()
+ tok_state = tok_state_script_data_double_escaped
+ return new_character_token "\ufffd"
+ if c is '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # Reconsume
+ return
+ # Anything else
+ tok_state = tok_state_script_data_double_escaped
+ return new_character_token c
+
+ # 8.2.4.32 http://www.w3.org/TR/html5/syntax.html#script-data-double-escaped-less-than-sign-state
+ tok_state_script_data_double_escaped_less_than_sign = ->
+ c = txt.charAt(cur++)
+ if c is '/'
+ temporary_buffer = ''
+ tok_state = tok_state_script_data_double_escape_end
+ return new_character_token '/'
+ # Anything else
+ tok_state = tok_state_script_data_double_escaped
+ cur -= 1 # Reconsume
+ return
+
+ # 8.2.4.33 http://www.w3.org/TR/html5/syntax.html#script-data-double-escape-end-state
+ tok_state_script_data_double_escape_end = ->
+ c = txt.charAt(cur++)
+ if c is "\t" or c is "\u000a" or c is "\u000c" or c is ' ' or c is '/' or c is '>'
+ if temporary_buffer is 'script'
+ tok_state = tok_state_script_data_escaped
+ else
+ tok_state = tok_state_script_data_double_escaped
+ return new_character_token c
+ if is_uc_alpha(c)
+ temporary_buffer += c.toLowerCase() # yes, really lowercase
+ return new_character_token c
+ if is_lc_alpha(c)
+ temporary_buffer += c
+ return new_character_token c
+ # Anything else
+ tok_state = tok_state_script_data_double_escaped
+ cur -= 1 # Reconsume
+ return
+
+ # 8.2.4.34 http://www.w3.org/TR/html5/syntax.html#before-attribute-name-state
+ tok_state_before_attribute_name = ->
+ attr_name = null
+ switch c = txt.charAt(cur++)
+ when "\t", "\n", "\u000c", ' '
+ return null
+ when '/'
+ tok_state = tok_state_self_closing_start_tag
+ return null
+ when '>'
+ tok_state = tok_state_data
+ tmp = tok_cur_tag
+ tok_cur_tag = null
+ return tmp
+ when "\u0000"
+ parse_error()
+ attr_name = "\ufffd"
+ when '"', "'", '<', '='
+ parse_error()
+ attr_name = c
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ else
+ if is_uc_alpha(c)
+ attr_name = c.toLowerCase()
+ else
+ attr_name = c
+ if attr_name?
+ tok_cur_tag.attrs_a.unshift [attr_name, '']
+ tok_state = tok_state_attribute_name
+ return null
+
+ # 8.2.4.35 http://www.w3.org/TR/html5/syntax.html#attribute-name-state
+ tok_state_attribute_name = ->
+ switch c = txt.charAt(cur++)
+ when "\t", "\n", "\u000c", ' '
+ tok_state = tok_state_after_attribute_name
+ when '/'
+ tok_state = tok_state_self_closing_start_tag
+ when '='
+ tok_state = tok_state_before_attribute_value
+ when '>'
+ tok_state = tok_state_data
+ tmp = tok_cur_tag
+ tok_cur_tag = null
+ return tmp
+ when "\u0000"
+ parse_error()
+ tok_cur_tag.attrs_a[0][0] += "\ufffd"
+ when '"', "'", '<'
+ parse_error()
+ tok_cur_tag.attrs_a[0][0] += c
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ else
+ if is_uc_alpha(c)
+ tok_cur_tag.attrs_a[0][0] += c.toLowerCase()
+ else
+ tok_cur_tag.attrs_a[0][0] += c
+ return null
+
+ # 8.2.4.36 http://www.w3.org/TR/html5/syntax.html#after-attribute-name-state
+ tok_state_after_attribute_name = ->
+ c = txt.charAt(cur++)
+ if c is "\t" or c is "\n" or c is "\u000c" or c is ' '
+ return
+ if c is '/'
+ tok_state = tok_state_self_closing_start_tag
+ return
+ if c is '='
+ tok_state = tok_state_before_attribute_value
+ return
+ if c is '>'
+ tok_state = tok_state_data
+ return
+ if is_uc_alpha(c)
+ tok_cur_tag.attrs_a.unshift [c.toLowerCase(), '']
+ tok_state = tok_state_attribute_name
+ return
+ if c is "\u0000"
+ parse_error()
+ tok_cur_tag.attrs_a.unshift ["\ufffd", '']
+ tok_state = tok_state_attribute_name
+ return
+ if c is '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # reconsume
+ return
+ if c is '"' or c is "'" or c is '<'
+ parse_error()
+ # fall through to Anything else
+ # Anything else
+ tok_cur_tag.attrs_a.unshift [c, '']
+ tok_state = tok_state_attribute_name
+
+ # 8.2.4.37 http://www.w3.org/TR/html5/syntax.html#before-attribute-value-state
+ tok_state_before_attribute_value = ->
+ switch c = txt.charAt(cur++)
+ when "\t", "\n", "\u000c", ' '
+ return null
+ when '"'
+ tok_state = tok_state_attribute_value_double_quoted
+ when '&'
+ tok_state = tok_state_attribute_value_unquoted
+ cur -= 1
+ when "'"
+ tok_state = tok_state_attribute_value_single_quoted
+ when "\u0000"
+ # Parse error
+ tok_cur_tag.attrs_a[0][1] += "\ufffd"
+ tok_state = tok_state_attribute_value_unquoted
+ when '>'
+ # Parse error
+ tok_state = tok_state_data
+ tmp = tok_cur_tag
+ tok_cur_tag = null
+ return tmp
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ else
+ tok_cur_tag.attrs_a[0][1] += c
+ tok_state = tok_state_attribute_value_unquoted
+ return null
+
+ # 8.2.4.38 http://www.w3.org/TR/html5/syntax.html#attribute-value-(double-quoted)-state
+ tok_state_attribute_value_double_quoted = ->
+ switch c = txt.charAt(cur++)
+ when '"'
+ tok_state = tok_state_after_attribute_value_quoted
+ when '&'
+ tok_cur_tag.attrs_a[0][1] += parse_character_reference '"', true
+ when "\u0000"
+ # Parse error
+ tok_cur_tag.attrs_a[0][1] += "\ufffd"
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ else
+ tok_cur_tag.attrs_a[0][1] += c
+ return null
+
+ # 8.2.4.39 http://www.w3.org/TR/html5/syntax.html#attribute-value-(single-quoted)-state
+ tok_state_attribute_value_single_quoted = ->
+ switch c = txt.charAt(cur++)
+ when "'"
+ tok_state = tok_state_after_attribute_value_quoted
+ when '&'
+ tok_cur_tag.attrs_a[0][1] += parse_character_reference "'", true
+ when "\u0000"
+ # Parse error
+ tok_cur_tag.attrs_a[0][1] += "\ufffd"
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ else
+ tok_cur_tag.attrs_a[0][1] += c
+ return null
+
+ # 8.2.4.40 http://www.w3.org/TR/html5/syntax.html#attribute-value-(unquoted)-state
+ tok_state_attribute_value_unquoted = ->
+ switch c = txt.charAt(cur++)
+ when "\t", "\n", "\u000c", ' '
+ tok_state = tok_state_before_attribute_name
+ when '&'
+ tok_cur_tag.attrs_a[0][1] += parse_character_reference '>', true
+ when '>'
+ tok_state = tok_state_data
+ tmp = tok_cur_tag
+ tok_cur_tag = null
+ return tmp
+ when "\u0000"
+ tok_cur_tag.attrs_a[0][1] += "\ufffd"
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ else
+ # Parse Error if ', <, = or ` (backtick)
+ tok_cur_tag.attrs_a[0][1] += c
+ return null
+
+ # 8.2.4.42 http://www.w3.org/TR/html5/syntax.html#after-attribute-value-(quoted)-state
+ tok_state_after_attribute_value_quoted = ->
+ switch c = txt.charAt(cur++)
+ when "\t", "\n", "\u000c", ' '
+ tok_state = tok_state_before_attribute_name
+ when '/'
+ tok_state = tok_state_self_closing_start_tag
+ when '>'
+ tok_state = tok_state_data
+ tmp = tok_cur_tag
+ tok_cur_tag = null
+ return tmp
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ else
+ # Parse Error
+ tok_state = tok_state_before_attribute_name
+ cur -= 1 # we didn't handle that char
+ return null
+
+ # 8.2.4.43 http://www.w3.org/TR/html5/syntax.html#self-closing-start-tag-state
+ tok_state_self_closing_start_tag = ->
+ c = txt.charAt(cur++)
+ if c is '>'
+ tok_cur_tag.flag 'self-closing', true
+ tok_state = tok_state_data
+ return tok_cur_tag
+ if c is ''
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # Reconsume
+ return
+ # Anything else
+ parse_error()
+ tok_state = tok_state_before_attribute_name
+ cur -= 1 # Reconsume
+ return
+
+ # 8.2.4.44 http://www.w3.org/TR/html5/syntax.html#bogus-comment-state
+ # WARNING: put a comment token in tok_cur_tag before setting this state
+ tok_state_bogus_comment = ->
+ next_gt = txt.indexOf '>', cur
+ if next_gt is -1
+ val = txt.substr cur
+ cur = txt.length
+ else
+ val = txt.substr cur, (next_gt - cur)
+ cur = next_gt + 1
+ val = val.replace(new RegExp("\u0000", 'g'), "\ufffd")
+ tok_cur_tag.text += val
+ tok_state = tok_state_data
+ return tok_cur_tag
+
+ # 8.2.4.45 http://www.w3.org/TR/html5/syntax.html#markup-declaration-open-state
+ tok_state_markup_declaration_open = ->
+ if txt.substr(cur, 2) is '--'
+ cur += 2
+ tok_cur_tag = new_comment_token ''
+ tok_state = tok_state_comment_start
+ return
+ if txt.substr(cur, 7).toLowerCase() is 'doctype'
+ cur += 7
+ tok_state = tok_state_doctype
+ return
+ acn = adjusted_current_node()
+ if acn and acn.namespace isnt NS_HTML and txt.substr(cur, 7) is '[CDATA['
+ cur += 7
+ tok_state = tok_state_cdata_section
+ return
+ # Otherwise
+ parse_error()
+ tok_cur_tag = new_comment_token ''
+ tok_state = tok_state_bogus_comment
+ return
+
+ # 8.2.4.46 http://www.w3.org/TR/html5/syntax.html#comment-start-state
+ tok_state_comment_start = ->
+ switch c = txt.charAt(cur++)
+ when '-'
+ tok_state = tok_state_comment_start_dash
+ when "\u0000"
+ parse_error()
+ tok_state = tok_state_comment
+ return new_character_token "\ufffd"
+ when '>'
+ parse_error()
+ tok_state = tok_state_data
+ return tok_cur_tag
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # Reconsume
+ return tok_cur_tag
+ else
+ tok_cur_tag.text += c
+ tok_state = tok_state_comment
+ return null
+
+ # 8.2.4.47 http://www.w3.org/TR/html5/syntax.html#comment-start-dash-state
+ tok_state_comment_start_dash = ->
+ switch c = txt.charAt(cur++)
+ when '-'
+ tok_state = tok_state_comment_end
+ when "\u0000"
+ parse_error()
+ tok_cur_tag.text += "-\ufffd"
+ tok_state = tok_state_comment
+ when '>'
+ parse_error()
+ tok_state = tok_state_data
+ return tok_cur_tag
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # Reconsume
+ return tok_cur_tag
+ else
+ tok_cur_tag.text += "-#{c}"
+ tok_state = tok_state_comment
+ return null
+
+ # 8.2.4.48 http://www.w3.org/TR/html5/syntax.html#comment-state
+ tok_state_comment = ->
+ switch c = txt.charAt(cur++)
+ when '-'
+ tok_state = tok_state_comment_end_dash
+ when "\u0000"
+ parse_error()
+ tok_cur_tag.text += "\ufffd"
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # Reconsume
+ return tok_cur_tag
+ else
+ tok_cur_tag.text += c
+ return null
+
+ # 8.2.4.49 http://www.w3.org/TR/html5/syntax.html#comment-end-dash-state
+ tok_state_comment_end_dash = ->
+ switch c = txt.charAt(cur++)
+ when '-'
+ tok_state = tok_state_comment_end
+ when "\u0000"
+ parse_error()
+ tok_cur_tag.text += "-\ufffd"
+ tok_state = tok_state_comment
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # Reconsume
+ return tok_cur_tag
+ else
+ tok_cur_tag.text += "-#{c}"
+ tok_state = tok_state_comment
+ return null
+
+ # 8.2.4.50 http://www.w3.org/TR/html5/syntax.html#comment-end-state
+ tok_state_comment_end = ->
+ switch c = txt.charAt(cur++)
+ when '>'
+ tok_state = tok_state_data
+ return tok_cur_tag
+ when "\u0000"
+ parse_error()
+ tok_cur_tag.text += "--\ufffd"
+ tok_state = tok_state_comment
+ when '!'
+ parse_error()
+ tok_state = tok_state_comment_end_bang
+ when '-'
+ parse_error()
+ tok_cur_tag.text += '-'
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # Reconsume
+ return tok_cur_tag
+ else
+ parse_error()
+ tok_cur_tag.text += "--#{c}"
+ tok_state = tok_state_comment
+ return null
+
+ # 8.2.4.51 http://www.w3.org/TR/html5/syntax.html#comment-end-bang-state
+ tok_state_comment_end_bang = ->
+ switch c = txt.charAt(cur++)
+ when '-'
+ tok_cur_tag.text += "--!#{c}"
+ tok_state = tok_state_comment_end_dash
+ when '>'
+ tok_state = tok_state_data
+ return tok_cur_tag
+ when "\u0000"
+ parse_error()
+ tok_cur_tag.text += "--!\ufffd"
+ tok_state = tok_state_comment
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ cur -= 1 # Reconsume
+ return tok_cur_tag
+ else
+ tok_cur_tag.text += "--!#{c}"
+ tok_state = tok_state_comment
+ return null
+
+ # 8.2.4.52 http://www.w3.org/TR/html5/syntax.html#doctype-state
+ tok_state_doctype = ->
+ switch c = txt.charAt(cur++)
+ when "\t", "\u000a", "\u000c", ' '
+ tok_state = tok_state_before_doctype_name
+ when '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ el = new_doctype_token ''
+ el.flag 'force-quirks', true
+ cur -= 1 # Reconsume
+ return el
+ else
+ parse_error()
+ tok_state = tok_state_before_doctype_name
+ cur -= 1 # Reconsume
+ return null
+
+ # 8.2.4.52 http://www.w3.org/TR/html5/syntax.html#doctype-state
+ tok_state_before_doctype_name = ->
+ c = txt.charAt(cur++)
+ if c is "\t" or c is "\u000a" or c is "\u000c" or c is ' '
+ return
+ if is_uc_alpha(c)
+ tok_cur_tag = new_doctype_token c.toLowerCase()
+ tok_state = tok_state_doctype_name
+ return
+ if c is "\u0000"
+ parse_error()
+ tok_cur_tag = new_doctype_token "\ufffd"
+ tok_state = tok_state_doctype_name
+ return
+ if c is '>'
+ parse_error()
+ el = new_doctype_token ''
+ el.flag 'force-quirks', true
+ tok_state = tok_state_data
+ return el
+ if c is '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ el = new_doctype_token ''
+ el.flag 'force-quirks', true
+ cur -= 1 # Reconsume
+ return el
+ # Anything else
+ tok_cur_tag = new_doctype_token c
+ tok_state = tok_state_doctype_name
+ return null
+
+ # 8.2.4.54 http://www.w3.org/TR/html5/syntax.html#doctype-name-state
+ tok_state_doctype_name = ->
+ c = txt.charAt(cur++)
+ if c is "\t" or c is "\u000a" or c is "\u000c" or c is ' '
+ tok_state = tok_state_after_doctype_name
+ return
+ if c is '>'
+ tok_state = tok_state_data
+ return tok_cur_tag
+ if is_uc_alpha(c)
+ tok_cur_tag.name += c.toLowerCase()
+ return
+ if c is "\u0000"
+ parse_error()
+ tok_cur_tag.name += "\ufffd"
+ return
+ if c is '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ tok_cur_tag.flag 'force-quirks', true
+ cur -= 1 # Reconsume
+ return tok_cur_tag
+ # Anything else
+ tok_cur_tag.name += c
+ return null
+
+ # 8.2.4.55 http://www.w3.org/TR/html5/syntax.html#after-doctype-name-state
+ tok_state_after_doctype_name = ->
+ c = txt.charAt(cur++)
+ if c is "\t" or c is "\u000a" or c is "\u000c" or c is ' '
+ return
+ if c is '>'
+ tok_state = tok_state_data
+ return tok_cur_tag
+ if c is '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ tok_cur_tag.flag 'force-quirks', true
+ cur -= 1 # Reconsume
+ return tok_cur_tag
+ # Anything else
+ if txt.substr(cur - 1, 6).toLowerCase() is 'public'
+ cur += 5
+ tok_state = tok_state_after_doctype_public_keyword
+ return
+ if txt.substr(cur - 1, 6).toLowerCase() is 'system'
+ cur += 5
+ tok_state = tok_state_after_doctype_system_keyword
+ return
+ parse_error()
+ tok_cur_tag.flag 'force-quirks', true
+ tok_state = tok_state_bogus_doctype
+ return null
+
+ # 8.2.4.56 http://www.w3.org/TR/html5/syntax.html#after-doctype-public-keyword-state
+ tok_state_after_doctype_public_keyword = ->
+ c = txt.charAt(cur++)
+ if c is "\t" or c is "\u000a" or c is "\u000c" or c is ' '
+ tok_state = tok_state_before_doctype_public_identifier
+ return
+ if c is '"'
+ parse_error()
+ tok_cur_tag.public_identifier = ''
+ tok_state = tok_state_doctype_public_identifier_double_quoted
+ return
+ if c is "'"
+ parse_error()
+ tok_cur_tag.public_identifier = ''
+ tok_state = tok_state_doctype_public_identifier_single_quoted
+ return
+ if c is '>'
+ parse_error()
+ tok_cur_tag.flag 'force-quirks', true
+ tok_state = tok_state_data
+ return tok_cur_tag
+ if c is '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ tok_cur_tag.flag 'force-quirks', true
+ cur -= 1 # Reconsume
+ return tok_cur_tag
+ # Anything else
+ parse_error()
+ tok_cur_tag.flag 'force-quirks', true
+ tok_state = tok_state_bogus_doctype
+ return null
+
+ # 8.2.4.57 http://www.w3.org/TR/html5/syntax.html#before-doctype-public-identifier-state
+ tok_state_before_doctype_public_identifier = ->
+ c = txt.charAt(cur++)
+ if c is "\t" or c is "\u000a" or c is "\u000c" or c is ' '
+ return
+ if c is '"'
+ parse_error()
+ tok_cur_tag.public_identifier = ''
+ tok_state = tok_state_doctype_public_identifier_double_quoted
+ return
+ if c is "'"
+ parse_error()
+ tok_cur_tag.public_identifier = ''
+ tok_state = tok_state_doctype_public_identifier_single_quoted
+ return
+ if c is '>'
+ parse_error()
+ tok_cur_tag.flag 'force-quirks', true
+ tok_state = tok_state_data
+ return tok_cur_tag
+ if c is '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ tok_cur_tag.flag 'force-quirks', true
+ cur -= 1 # Reconsume
+ return tok_cur_tag
+ # Anything else
+ parse_error()
+ tok_cur_tag.flag 'force-quirks', true
+ tok_state = tok_state_bogus_doctype
+ return null
+
+
+ # 8.2.4.58 http://www.w3.org/TR/html5/syntax.html#doctype-public-identifier-(double-quoted)-state
+ tok_state_doctype_public_identifier_double_quoted = ->
+ c = txt.charAt(cur++)
+ if c is '"'
+ tok_state = tok_state_after_doctype_public_identifier
+ return
+ if c is "\u0000"
+ parse_error()
+ tok_cur_tag.public_identifier += "\ufffd"
+ return
+ if c is '>'
+ parse_error()
+ tok_cur_tag.flag 'force-quirks', true
+ tok_state = tok_state_data
+ return tok_cur_tag
+ if c is '' # EOF
+ parse_error()
+ tok_state = tok_state_data
+ tok_cur_tag.flag 'force-quirks', true
+ cur -= 1 # Reconsume
+ return tok_cur_tag
+ # Anything else
+ tok_cur_tag.public_identifier += c