diff options
| author | Oskari Timperi <oskari.timperi@iki.fi> | 2017-12-05 19:27:09 +0200 |
|---|---|---|
| committer | Oskari Timperi <oskari.timperi@iki.fi> | 2017-12-05 19:27:09 +0200 |
| commit | 7ee6dfc00d26bd41b334386115dd2a58cfd80aab (patch) | |
| tree | fb4d6ae992a7b683d6b938ae205104b1279595d4 /examples/dump.nim | |
| download | nim-gumbo-parser-7ee6dfc00d26bd41b334386115dd2a58cfd80aab.tar.gz nim-gumbo-parser-7ee6dfc00d26bd41b334386115dd2a58cfd80aab.zip | |
Diffstat (limited to 'examples/dump.nim')
| -rw-r--r-- | examples/dump.nim | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/examples/dump.nim b/examples/dump.nim new file mode 100644 index 0000000..a59aed7 --- /dev/null +++ b/examples/dump.nim @@ -0,0 +1,48 @@ +import gumbo_parser +import strutils + +let data = """ + <!DOCTYPE html> +<html> +<head> +<meta charset="UTF-8"> +<title>Title of the document</title> +</head> + +<body> +Content of the document...... +<p>a nice paragraph <b class="my-bold">with some bold text</b></p> +</body> + +</html> +""" + +let output = gumboParse(data) + +proc dump(node: ptr GumboNode, depth: int) = + let indent = repeat(' ', depth) + let indent1 = repeat(' ', depth + 1) + let indent2 = repeat(' ', depth + 2) + + echo(indent, node.`type`) + + case node.`type` + of GumboNodeDocument: + echo(indent1, "name: ", node.v.document.name) + echo(indent1, "public: ", node.v.document.publicIdentifier) + echo(indent1, "system: ", node.v.document.systemIdentifier) + echo(indent1, "quirks: ", node.v.document.docTypeQuirksMode) + for child in children(node.v.document): + dump(child, depth+1) + of GumboNodeElement: + echo(indent1, "tag: ", gumboNormalizedTagName(node.v.element.tag)) + echo(indent1, "attributes:") + for attribute in attributes(node.v.element): + echo(indent2, attribute.name, ": ", attribute.value) + for child in children(node.v.element): + dump(child, depth+1) + of GumboNodeText, GumboNodeCData, GumboNodeComment: + echo(indent1, node.v.text.text) + else: discard + +dump(output.document, 0) |
