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/htmlparser.nim | |
parent | 683cf2ee3ce2fbf6304839d3b68236228fc8dff2 (diff) | |
download | chawan-f4c263645df79e2dad8c107eb502851d6e2ad8de.tar.gz |
htmltokenizer: implement a small todo
Diffstat (limited to 'src/html/htmlparser.nim')
-rw-r--r-- | src/html/htmlparser.nim | 16 |
1 files changed, 11 insertions, 5 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: |