about summary refs log tree commit diff stats
path: root/src/html/parser.nim
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2021-11-12 16:55:53 +0100
committerbptato <nincsnevem662@gmail.com>2021-11-12 16:55:53 +0100
commit7108754641cefb3f01af8e29aae11695d94e980c (patch)
treec191a33745da13d31131fa8186bcfbe58ff69488 /src/html/parser.nim
parentfcd3a5b204e15fdfc739fd04975977d288e892e0 (diff)
downloadchawan-7108754641cefb3f01af8e29aae11695d94e980c.tar.gz
Colors, italic, bold, read from pipe
Diffstat (limited to 'src/html/parser.nim')
-rw-r--r--src/html/parser.nim11
1 files changed, 7 insertions, 4 deletions
diff --git a/src/html/parser.nim b/src/html/parser.nim
index eed5baa7..68295dbe 100644
--- a/src/html/parser.nim
+++ b/src/html/parser.nim
@@ -225,8 +225,6 @@ proc processDocumentEndNode(state: var HTMLParseState) =
   state.elementNode = state.elementNode.parentElement
 
 proc processDocumentText(state: var HTMLParseState) =
-  if state.textNode != nil and state.textNode.data.len > 0:
-    processDocumentBody(state)
   if state.textNode == nil:
     state.textNode = newText()
     processDocumentAddNode(state, state.textNode)
@@ -264,11 +262,16 @@ proc processDocumentStartElement(state: var HTMLParseState, element: Element, ta
     add = false
   of TAG_HEAD:
     add = false
+    state.in_body = false
+    if state.elementNode.ownerDocument != nil:
+      state.elementNode = state.elementNode.ownerDocument.head
   of TAG_BODY:
     add = false
-    processDocumentBody(state)
   else: discard
 
+  if not state.in_body and not (element.tagType in HeadTagTypes):
+    processDocumentBody(state)
+
   if state.elementNode.nodeType == ELEMENT_NODE:
     case element.tagType
     of SelfClosingTagTypes:
@@ -302,7 +305,7 @@ proc processDocumentEndElement(state: var HTMLParseState, tag: DOMParsedTag) =
   if tag.tagid in VoidTagTypes:
     return
   if tag.tagid == TAG_HEAD:
-    state.in_body = true
+    processDocumentBody(state)
     return
   if tag.tagid == TAG_BODY:
     return