JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fix two more parser bugs
authorJason Woofenden <jason@jasonwoof.com>
Thu, 24 Dec 2015 17:06:07 +0000 (12:06 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 24 Dec 2015 17:06:07 +0000 (12:06 -0500)
parse-html.coffee

index adb9bab..487fe99 100644 (file)
@@ -1924,11 +1924,7 @@ parse_html = (args) ->
                if t.type is TYPE_START_TAG and (t.name is 'pre' or t.name is 'listing')
                        close_p_if_in_button_scope()
                        insert_html_element t
-                       # spec: If the next token is a "LF" (U+000A) character token, then
-                       # ignore that token and move on to the next one. (Newlines at the
-                       # start of pre blocks are ignored as an authoring convenience.)
-                       if txt.charAt(cur) is "\u000a" # FIXME check for crlf?
-                               cur += 1
+                       eat_next_token_if_newline()
                        flag_frameset_ok = false
                        return
                if t.type is TYPE_START_TAG and t.name is 'form'
@@ -2239,8 +2235,7 @@ parse_html = (args) ->
                        return
                if t.type is TYPE_START_TAG and t.name is 'textarea'
                        insert_html_element t
-                       if txt.charAt(cur) is "\u000a" # FIXME check for crlf?
-                               cur += 1
+                       eat_next_token_if_newline()
                        tok_state = tok_state_rcdata
                        original_ins_mode = ins_mode
                        flag_frameset_ok = false
@@ -2771,7 +2766,7 @@ parse_html = (args) ->
                        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', NS_HTML
+                       unless is_in_select_scope 'select', NS_HTML
                                return
                        loop
                                el = open_els.shift()
@@ -4640,6 +4635,24 @@ parse_html = (args) ->
                                        return '&'
                return # never reached
 
+       eat_next_token_if_newline = ->
+               old_cur = cur
+               t = null
+               until t?
+                       t = tok_state()
+               if t.type is TYPE_TEXT
+                       # definition of a newline depends on whether it was a character ref or not
+                       if cur - old_cur is 1
+                               # not a character reference
+                               if t.text is "\u000d" or t.text is "\u000a"
+                                       return
+                       else
+                               if t.text is "\u000a"
+                                       return
+               # not a "newline"
+               cur = old_cur
+               return
+
        # tree constructor initialization
        # see comments on TYPE_TAG/etc for the structure of this data
        txt = args.html
@@ -4676,11 +4689,13 @@ parse_html = (args) ->
                console.log "hi"
        # proccess input
        # http://www.w3.org/TR/html5/syntax.html#tree-construction
-       while flag_parsing
-               t = tok_state()
-               if t?
-                       process_token t
-                       # fixfull parse error if has self-closing flag, but it wasn't acknolwedged
+       parse_main_loop = ->
+               while flag_parsing
+                       t = tok_state()
+                       if t?
+                               process_token t
+                               # fixfull parse error if has self-closing flag, but it wasn't acknolwedged
+       parse_main_loop()
        return doc.children
 
 serialize_els = (els, shallow, show_ids) ->