odin-html

HTML Parsing library in Odin.
Log | Files | Refs | README | LICENSE

commit 5fe432844dcdb51f0ae5b3f5ce84d29cc1e97931
parent 8a232ba64047f76d21d01eafa423676a66332167
Author: Jack Mordaunt <jackmordaunt.dev@gmail.com>
Date:   Thu, 23 Jul 2026 21:47:04 -0300

example: refactor to new api

Diffstat:
Mexample/main.odin | 26++++++++++++++++++++++----
1 file changed, 22 insertions(+), 4 deletions(-)

diff --git a/example/main.odin b/example/main.odin @@ -5,12 +5,30 @@ import "core:fmt" main :: proc() { doc := html.parse("<html><ul><li>one</li><li>two</li><li>three</li></ul></html>") - defer html.document_delete(doc) + defer html.document_delete(&doc) - iter := html.node_iterator_from_document(doc) + walk(&doc, 0, 0) +} + +walk :: proc(doc: ^html.Document, ref: html.Node_Ref, depth: int) { + for d in 0 ..< depth { + fmt.print(" ") + } + switch html.node_kind(doc, ref) { + case .Element: + fmt.printfln("<%s>", html.node_name(doc, ref)) + case .Text: + fmt.printfln("text: %q", html.node_text(doc, ref)) + case .Comment: + fmt.printfln("<!-- %q -->", html.node_text(doc, ref)) + case .Doctype: + fmt.printfln("<!doctype %q>", html.node_text(doc, ref)) + } + + it := html.node_children(doc, ref) - for node in html.node_iterator_depth_first(&iter) { - fmt.println(html.node_to_string(node)) + for child in html.next(&it) { + walk(doc, child, depth + 1) } }