about summary refs log tree commit diff stats
path: root/src/html
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2022-08-23 18:06:28 +0200
committerbptato <nincsnevem662@gmail.com>2022-08-23 18:06:28 +0200
commit4eaa8830145aa78e37c0c21fd943a6de24adc9df (patch)
tree755668bffe53cebe3fc65db5d7cf45fb73d653a6 /src/html
parentfbdb7fc79716d5b036945cd33e03e6b693ab957f (diff)
downloadchawan-4eaa8830145aa78e37c0c21fd943a6de24adc9df.tar.gz
Fix nth-child bugs, rename select to match
Diffstat (limited to 'src/html')
-rw-r--r--src/html/dom.nim18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/html/dom.nim b/src/html/dom.nim
index e404f18b..4bf73302 100644
--- a/src/html/dom.nim
+++ b/src/html/dom.nim
@@ -164,17 +164,29 @@ type
     #TODO result
 
 # For debugging
+proc tostr(ftype: enum): string =
+  return ($ftype).split('_')[1..^1].join("-").tolower()
+
 func `$`*(node: Node): string =
   if node == nil: return "nil"
   case node.nodeType
   of ELEMENT_NODE:
     let element = Element(node)
-    "Element of " & $element.tagType & ", children: {\n" & $element.childNodes & "\n}"
+    result = "<" & $element.tagType.tostr()
+    for k, v in element.attributes:
+      result &= ' ' & k & (if v != "": "=\"" & v & "\"" else: "")
+    result &= ">\n"
+    for node in element.childNodes:
+      for line in ($node).split('\n'):
+        result &= "\t" & line & "\n"
+    result &= "</" & $element.tagType.tostr() & ">"
   of TEXT_NODE:
     let text = Text(node)
-    "Text: " & text.data
+    result = text.data
+  of COMMENT_NODE:
+    result = "<!-- " & Comment(node).data & "-->"
   else:
-    "Node of " & $node.nodeType
+    result = "Node of " & $node.nodeType
 
 iterator children*(node: Node): Element {.inline.} =
   for child in node.childNodes: