about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-07-08 00:08:00 +0200
committerbptato <nincsnevem662@gmail.com>2023-07-08 00:08:00 +0200
commit51603f8865063d39c99dde10ba89528a7ed312c5 (patch)
tree3337c1b9986f328d97b256e6558f72d63a50cab8 /src
parent45f58316b4da12e893856e47a4296ee09c49449e (diff)
downloadchawan-51603f8865063d39c99dde10ba89528a7ed312c5.tar.gz
Add StyledNode stringifier for debugging
Diffstat (limited to 'src')
-rw-r--r--src/css/stylednode.nim14
1 files changed, 14 insertions, 0 deletions
diff --git a/src/css/stylednode.nim b/src/css/stylednode.nim
index 0eac3c66..c9358b90 100644
--- a/src/css/stylednode.nim
+++ b/src/css/stylednode.nim
@@ -62,6 +62,20 @@ type
     of STYLED_REPLACEMENT: # replaced elements: quotes, or (TODO) markers, images
       content*: CSSContent
 
+# For debugging
+func `$`*(node: StyledNode): string =
+  if node == nil:
+    return "nil"
+  case node.t
+  of STYLED_TEXT:
+    return "#text " & node.text
+  of STYLED_ELEMENT:
+    if node.node != nil:
+      return $node.node
+    return $node.pseudo
+  of STYLED_REPLACEMENT:
+    return "#replacement"
+
 iterator branch*(node: StyledNode): StyledNode {.inline.} =
   var node = node
   while node != nil: