odin-html

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

main.odin (740B)


      1 package main
      2 
      3 import html "../"
      4 import "core:fmt"
      5 
      6 main :: proc() {
      7 	doc := html.parse("<html><ul><li>one</li><li>two</li><li>three</li></ul></html>")
      8 	defer html.document_delete(&doc)
      9 
     10 	walk(&doc, 0, 0)
     11 }
     12 
     13 walk :: proc(doc: ^html.Document, ref: html.Node_Ref, depth: int) {
     14 	for d in 0 ..< depth {
     15 		fmt.print("  ")
     16 	}
     17 	switch html.node_kind(doc, ref) {
     18 	case .Element:
     19 		fmt.printfln("<%s>", html.node_name(doc, ref))
     20 	case .Text:
     21 		fmt.printfln("text: %q", html.node_text(doc, ref))
     22 	case .Comment:
     23 		fmt.printfln("<!-- %q -->", html.node_text(doc, ref))
     24 	case .Doctype:
     25 		fmt.printfln("<!doctype %q>", html.node_text(doc, ref))
     26 	}
     27 
     28 	it := html.node_children(doc, ref)
     29 
     30 	for child in html.next(&it) {
     31 		walk(doc, child, depth + 1)
     32 	}
     33 }
     34