From 7ee6dfc00d26bd41b334386115dd2a58cfd80aab Mon Sep 17 00:00:00 2001 From: Oskari Timperi Date: Tue, 5 Dec 2017 19:27:09 +0200 Subject: Initial commit --- examples/dump.nim | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ examples/nim.cfg | 1 + 2 files changed, 49 insertions(+) create mode 100644 examples/dump.nim create mode 100644 examples/nim.cfg (limited to 'examples') 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 = """ + + + + +Title of the document + + + +Content of the document...... +

a nice paragraph with some bold text

+ + + +""" + +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) diff --git a/examples/nim.cfg b/examples/nim.cfg new file mode 100644 index 0000000..0f840a1 --- /dev/null +++ b/examples/nim.cfg @@ -0,0 +1 @@ +--path:".." -- cgit v1.2.3