From fcaaf0f85eb620893b85f5efcb8d894b68793cd9 Mon Sep 17 00:00:00 2001 From: Jason Woofenden Date: Thu, 24 Dec 2015 11:26:44 -0500 Subject: [PATCH] fix noah's ark and empty cdata --- parse-html.coffee | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/parse-html.coffee b/parse-html.coffee index 3d4db84..b3b3f7f 100644 --- a/parse-html.coffee +++ b/parse-html.coffee @@ -668,18 +668,29 @@ parse_html = (args) -> else console.log "Parse error at character #{cur} of #{txt.length}" + # http://www.w3.org/TR/html5/syntax.html#push-onto-the-list-of-active-formatting-elements + # "Noah's Ark clause" but with three afe_push = (new_el) -> matches = 0 for el, i in afe + if el.type is TYPE_AFE_MARKER + break if el.name is new_el.name and el.namespace is new_el.namespace + attrs_match = true for k, v of el.attrs - continue unless new_el.attrs[k] is v - for k, v of new_el.attrs - continue unless el.attrs[k] is v - matches += 1 - if matches is 3 - afe.splice i, 1 - break + unless new_el.attrs[k] is v + attrs_match = false + break + if attrs_match + for k, v of new_el.attrs + unless el.attrs[k] is v + attrs_match = false + break + if attrs_match + matches += 1 + if matches is 3 + afe.splice i, 1 + break afe.unshift new_el afe_push_marker = -> afe.unshift new_afe_marker() @@ -4525,7 +4536,9 @@ parse_html = (args) -> else val = txt.substr cur, (next_gt - cur) cur = next_gt + 3 - return new_character_token val # fixfull split + if val.length > 0 + return new_character_token val # fixfull split + return null # 8.2.4.69 http://www.w3.org/TR/html5/syntax.html#consume-a-character-reference # Don't set this as a state, just call it @@ -4648,7 +4661,7 @@ parse_html = (args) -> txt = txt.replace(new RegExp("\r\n", 'g'), "\n") # fixfull spec doesn't say this txt = txt.replace(new RegExp("\r", 'g'), "\n") # fixfull spec doesn't say this - if args.name is "tests20.dat #22" + if args.name is "tests23.dat #1" console.log "hi" # proccess input # http://www.w3.org/TR/html5/syntax.html#tree-construction -- 1.7.10.4