diff options
author | bptato <nincsnevem662@gmail.com> | 2022-12-15 18:13:10 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2022-12-15 18:13:10 +0100 |
commit | f4c263645df79e2dad8c107eb502851d6e2ad8de (patch) | |
tree | e4d5cb6facc534bfc569a174d3fb731579ccb2ab /src/html | |
parent | 683cf2ee3ce2fbf6304839d3b68236228fc8dff2 (diff) | |
download | chawan-f4c263645df79e2dad8c107eb502851d6e2ad8de.tar.gz |
htmltokenizer: implement a small todo
Diffstat (limited to 'src/html')
-rw-r--r-- | src/html/htmlparser.nim | 16 | ||||
-rw-r--r-- | src/html/htmltokenizer.nim | 4 |
2 files changed, 13 insertions, 7 deletions
diff --git a/src/html/htmlparser.nim b/src/html/htmlparser.nim index ebdc6645..a9952f11 100644 --- a/src/html/htmlparser.nim +++ b/src/html/htmlparser.nim @@ -231,7 +231,7 @@ proc insertForeignElement(parser: var HTML5Parser, token: Token, namespace: Name if location.inside.preInsertionValidity(element, location.before): #TODO custom elements location.insert(element) - parser.openElements.add(element) + parser.pushElement(element) return element proc insertHTMLElement(parser: var HTML5Parser, token: Token): Element = @@ -462,10 +462,16 @@ proc genericRCDATAElementParsingAlgorithm(parser: var HTML5Parser, token: Token) parser.oldInsertionMode = parser.insertionMode parser.insertionMode = TEXT +proc pushElement(parser: var HTML5Parser, node: Element) = + parser.openElements.add(node) + parser.tokenizer.hasnonhtml = not node.inHTMLNamespace() + proc popElement(parser: var HTML5Parser): Element = result = parser.openElements.pop() if result.tagType == TAG_TEXTAREA: result.resetElement() + if parser.openElements.len == 0: + parser.tokenizer.hasnonhtml = false # 13.2.6.3 proc generateImpliedEndTags(parser: var HTML5Parser) = @@ -826,7 +832,7 @@ proc processInHTMLContent(parser: var HTML5Parser, token: Token, insertionMode = "<html>" => (block: let element = parser.createElement(token, Namespace.HTML, parser.document) parser.document.append(element) - parser.openElements.add(element) + parser.pushElement(element) parser.insertionMode = BEFORE_HEAD ) ("</head>", "</body>", "</html>", "</br>") => (block: anything_else) @@ -834,7 +840,7 @@ proc processInHTMLContent(parser: var HTML5Parser, token: Token, insertionMode = _ => (block: let element = parser.document.newHTMLElement(TAG_HTML, Namespace.HTML) parser.document.append(element) - parser.openElements.add(element) + parser.pushElement(element) parser.insertionMode = BEFORE_HEAD reprocess token ) @@ -897,7 +903,7 @@ proc processInHTMLContent(parser: var HTML5Parser, token: Token, insertionMode = element.alreadyStarted = true #TODO document.write (?) location.insert(element) - parser.openElements.add(element) + parser.pushElement(element) parser.tokenizer.state = SCRIPT_DATA parser.oldInsertionMode = parser.insertionMode parser.insertionMode = TEXT @@ -971,7 +977,7 @@ proc processInHTMLContent(parser: var HTML5Parser, token: Token, insertionMode = ) ("<base>", "<basefont>", "<bgsound>", "<link>", "<meta>", "<noframes>", "<script>", "<style>", "<template>", "<title>") => (block: parse_error - parser.openElements.add(parser.head) + parser.pushElement(parser.head) parser.processInHTMLContent(token, IN_HEAD) for i in countdown(parser.openElements.high, 0): if parser.openElements[i] == parser.head: diff --git a/src/html/htmltokenizer.nim b/src/html/htmltokenizer.nim index d09f54dd..5053af97 100644 --- a/src/html/htmltokenizer.nim +++ b/src/html/htmltokenizer.nim @@ -23,6 +23,7 @@ type attrn: string attrv: string attr: bool + hasnonhtml*: bool decoder: DecoderStream sbuf: seq[Rune] @@ -237,7 +238,6 @@ iterator tokenize*(tokenizer: var Tokenizer): Token = cast[char](r) else: char(128) - template has_adjusted_current_node(): bool = false #TODO implement this template consume_and_discard(n: int) = #TODO optimize var i = 0 while i < n: @@ -939,7 +939,7 @@ iterator tokenize*(tokenizer: var Tokenizer): Token = of '[': if peek_str("CDATA["): consume_and_discard "CDATA[".len - if has_adjusted_current_node: #TODO and it is not an element in the HTML namespace + if tokenizer.hasnonhtml: switch_state CDATA_SECTION else: parse_error cdata_in_html_content |