JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
update aaa to WHATWG version
authorJason Woofenden <jason@jasonwoof.com>
Thu, 24 Dec 2015 14:01:03 +0000 (09:01 -0500)
committerJason Woofenden <jason@jasonwoof.com>
Thu, 24 Dec 2015 14:01:03 +0000 (09:01 -0500)
parse-html.coffee

index 581002b..f5437c9 100644 (file)
@@ -24,7 +24,7 @@
 #
 # Deviations from that spec:
 #
-#   Purposeful: search this file for "WTAG"
+#   Purposeful: search this file for "WHATWG"
 #
 #   Not finished yet: search this file for "fixfull", "TODO" and "FIXME"
 
@@ -342,7 +342,7 @@ special_elements = {
        img:NS_HTML, input:NS_HTML, isindex:NS_HTML, li:NS_HTML, link:NS_HTML,
        listing:NS_HTML, main:NS_HTML, marquee:NS_HTML,
 
-       menu:NS_HTML,menuitem:NS_HTML, # WATWG adds these
+       menu:NS_HTML,menuitem:NS_HTML, # WHATWG adds these
 
        meta:NS_HTML, nav:NS_HTML, noembed:NS_HTML, noframes:NS_HTML,
        noscript:NS_HTML, object:NS_HTML, ol:NS_HTML, p:NS_HTML, param:NS_HTML,
@@ -468,7 +468,7 @@ svg_attribute_fixes = {
        diffuseconstant: 'diffuseConstant'
        edgemode: 'edgeMode'
        externalresourcesrequired: 'externalResourcesRequired'
-       # WTAG removes this: filterres: 'filterRes'
+       # WHATWG removes this: filterres: 'filterRes'
        filterunits: 'filterUnits'
        glyphref: 'glyphRef'
        gradienttransform: 'gradientTransform'
@@ -896,16 +896,46 @@ parse_html = (args) ->
                debug_log "tree: #{serialize_els doc.children, false, true}"
                debug_log "open_els: #{serialize_els open_els, true, true}"
                debug_log "afe: #{serialize_els afe, true, true}"
-               # FIXME CONTINUE do WATWG thing here
+# this block implements tha W3C spec
+#              # 1. If the current node is an HTML element whose tag name is subject,
+#              # then run these substeps:
+#              #
+#              # 1. Let element be the current node.
+#              #
+#              # 2. Pop element off the stack of open elements.
+#              #
+#              # 3. If element is also in the list of active formatting elements,
+#              # remove the element from the list.
+#              #
+#              # 4. Abort the adoption agency algorithm.
+#              if open_els[0].name is subject and open_els[0].namespace is NS_HTML
+#                      el = open_els.shift()
+#                      # remove it from the list of active formatting elements (if found)
+#                      for t, i in afe
+#                              if t is el
+#                                      afe.splice i, 1
+#                                      break
+#                      debug_log "aaa: starting off with subject on top of stack, exiting"
+#                      return
+# WHATWG: https://html.spec.whatwg.org/multipage/syntax.html#adoption-agency-algorithm
+               # If the current node is an HTML element whose tag name is subject, and
+               # the current node is not in the list of active formatting elements,
+               # then pop the current node off the stack of open elements, and abort
+               # these steps.
                if open_els[0].name is subject and open_els[0].namespace is NS_HTML
-                       el = open_els.shift()
+                       debug_log "aaa: starting off with subject on top of stack, exiting"
                        # remove it from the list of active formatting elements (if found)
-                       for t, i in afe
-                               if t is el
-                                       afe.splice i, 1
+                       in_afe = false
+                       for el, i in afe
+                               if el is open_els[0]
+                                       in_afe = true
                                        break
-                       debug_log "aaa: starting off with subject on top of stack, exiting"
-                       return
+                       unless in_afe
+                               debug_log "aaa: ...and not in afe, aaa done"
+                               open_els.shift()
+                               return
+                       # fall through
+# END WHATWG
                outer = 0
                loop
                        if outer >= 8
@@ -2138,7 +2168,7 @@ parse_html = (args) ->
 #                                      parse_error()
 #                      insert_html_element t
 #                      return
-# below implements the WATWG spec https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody
+# below implements the WHATWG spec https://html.spec.whatwg.org/multipage/syntax.html#parsing-main-inbody
                if t.type is TYPE_START_TAG and (t.name is 'rb' or t.name is 'rtc')
                        if is_in_scope 'ruby', NS_HTML
                                generate_implied_end_tags()
@@ -2153,7 +2183,7 @@ parse_html = (args) ->
                                        parse_error()
                        insert_html_element t
                        return
-# end WATWG chunk
+# end WHATWG chunk
                if t.type is TYPE_START_TAG and t.name is 'math'
                        reconstruct_afe()
                        adjust_mathml_attributes t
@@ -4507,6 +4537,7 @@ parse_html = (args) ->
        head_element_pointer = null
        flag_fragment_parsing = false # parser originally created as part of the html fragment parsing algorithm (fragment case)
        context_element = null # FIXME initialize from args.fragment http://www.w3.org/TR/html5/syntax.html#parsing-html-fragments
+       prev_node_id = 0 # just for debugging
 
        # tokenizer initialization
        tok_state = tok_state_data