odin-html

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

README.md (1154B)


      1 # html
      2 
      3 This package offers a simple HTML parser, motivated by a desire to query the DOM and
      4 extract information from it.
      5 
      6 The current parser is NOT spec compliant, and is not guaranteed to work on _all_ HTML input.
      7 This may change.
      8 
      9 ## usage
     10 
     11 ```
     12 package main
     13 
     14 import html "../"
     15 import "core:fmt"
     16 
     17 main :: proc() {
     18 	doc := html.parse("<html><ul><li>one</li><li>two</li><li>three</li></ul></html>")
     19 	defer html.document_delete(doc)
     20 
     21 	iter := html.node_iterator_from_document(doc)
     22 
     23 	for node in html.node_iterator_depth_first(&iter) {
     24 		fmt.println(html.node_to_string(node))
     25 	}
     26 }
     27 ```
     28 
     29 All strings on the Node are a slice into the original input string.
     30 The dynamic arrays for the attributes and children can be deleted with [html.document_delete].
     31 
     32 ## roadmap 
     33 
     34 - record parse errors
     35 - spec compliance
     36   - respect content model: eg special hadling for `<script>`, `<pre>`, etc
     37 - stream in source data with a reader
     38 - support unicode input instead of just ascii
     39 
     40 ## potholes
     41 
     42 Special tags like `<script>` are not handled specially. Such a tag is expected to have it's inner HTML 
     43 be raw text. This version of the parser will parse script content as HTML.