From 0b40abbaa7fdfe6bd0150fd25456e7207d58ba1f Mon Sep 17 00:00:00 2001 From: bptato Date: Sun, 23 Jan 2022 16:28:36 +0100 Subject: Infer that we're in document body for text --- src/html/parser.nim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/html/parser.nim b/src/html/parser.nim index febe3bce..ca505135 100644 --- a/src/html/parser.nim +++ b/src/html/parser.nim @@ -369,6 +369,10 @@ proc processDocumentPart(state: var HTMLParseState, buf: string) = if state.in_comment: state.commentNode.data &= c else: + if not c.isWhitespace() and (state.textNode == nil or state.textNode.parentElement.tagType == TAG_HTML): + state.textNode = nil + processDocumentBody(state) + processDocumentText(state) if not (state.skip_lf and c == '\n'): processDocumentText(state) state.textNode.data &= c @@ -410,8 +414,7 @@ proc processDocumentPart(state: var HTMLParseState, buf: string) = let comment = newComment() state.commentNode = comment processDocumentAddNode(state, comment) - if state.textNode != nil: - state.textNode = nil + state.textNode = nil else: #TODO for doctype while p < max and buf[p] != '>': @@ -420,8 +423,7 @@ proc processDocumentPart(state: var HTMLParseState, buf: string) = continue if not state.in_comment: - if state.textNode != nil: - state.textNode = nil + state.textNode = nil p = at if state.in_script: if buf.has(""): -- cgit 1.4.1-2-gfad0