about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-01-23 16:28:36 +0100
committerbptato <nincsnevem662@gmail.com>2022-01-23 16:29:53 +0100
commit0b40abbaa7fdfe6bd0150fd25456e7207d58ba1f (patch)
treeb7e903ef95ced7ef33de86727a6e343010d6d8e7 /src
parent9dc1c7da62ff00fc8f9796f570902daefd7341af (diff)
downloadchawan-0b40abbaa7fdfe6bd0150fd25456e7207d58ba1f.tar.gz
Infer that we're in document body for text
Diffstat (limited to 'src')
-rw-r--r--src/html/parser.nim10
1 files changed, 6 insertions, 4 deletions
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("</script>"):