Skip to main content

treesitter_types_html/
lib.rs

1//! Strongly-typed AST types for HTML, auto-generated from
2//! [`tree-sitter-html`](https://docs.rs/tree-sitter-html)'s `node-types.json`.
3//!
4//! This crate is generated by [`treesitter-types`](https://docs.rs/treesitter-types) and is
5//! automatically kept up to date when a new version of the grammar crate is released.
6//!
7//! These types have been tested by parsing the
8//! [NiceHashQuickMiner](https://github.com/nicehash/NiceHashQuickMiner) source code.
9//!
10//! See the [Tree-sitter](https://tree-sitter.github.io/tree-sitter/) project for more
11//! information about the underlying parser framework.
12//!
13//! # Example
14//!
15//! ```
16//! use treesitter_types_html::*;
17//!
18//! // A minimal HTML document.
19//! let src = b"\
20//! <!DOCTYPE html>
21//! <html>
22//!   <body>
23//!     <h1>Hello, World!</h1>
24//!   </body>
25//! </html>
26//! ";
27//!
28//! // Parse the source with tree-sitter and convert into typed AST.
29//! let mut parser = tree_sitter::Parser::new();
30//! parser.set_language(&tree_sitter_html::LANGUAGE.into()).unwrap();
31//! let tree = parser.parse(src, None).unwrap();
32//! let document = Document::from_node(tree.root_node(), src).unwrap();
33//!
34//! // The document contains the doctype and the <html> element.
35//! assert!(!document.children.is_empty());
36//!
37//! // The first child is the doctype declaration.
38//! let DocumentChildren::Doctype(doctype) = &document.children[0] else {
39//!     panic!("expected a doctype");
40//! };
41//! assert_eq!(doctype.span.start.row, 0);
42//!
43//! // The second child is the <html> element.
44//! let DocumentChildren::Element(html_elem) = &document.children[1] else {
45//!     panic!("expected an element");
46//! };
47//! // The <html> element contains child elements (<body>, text, etc.).
48//! assert!(!html_elem.children.is_empty());
49//! ```
50
51pub use tree_sitter_html;
52pub use treesitter_types::tree_sitter;
53pub use treesitter_types::{FromNode, LeafNode, ParseError, Span, Spanned};
54
55mod generated;
56pub use generated::*;