1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
//! [![github]](https://github.com/Roba1993/lithtml)
//! [github]: https://img.shields.io/badge/github-8da0cb?style=for-the-badge&labelColor=555555&logo=github
//!
//! # lithtml
//! A lightweight and fast HTML/XHTML parser for Rust, designed to handle both full HTML documents and fragments.
//! This parser uses [Pest](https://pest.rs/) for parsing and is forked from [html-parser](https://github.com/mathiversen/html-parser).
//!
//! ## Features
//! - Parse html & xhtml (not xml processing instructions)
//! - Parse html-documents
//! - Parse html-fragments
//! - Parse empty documents
//! - Parse with the same api for both documents and fragments
//! - Parse custom, non-standard, elements; `<cat/>`, `<Cat/>` and `<C4-t/>`
//! - Removes comments
//! - Removes dangling elements
//! - Iterate over all nodes in the dom three
//!
//! ## Examples
//!
//! Parse html document and print as json & formatted dom
//! ```rust
//! use lithtml::Dom;
//!
//! fn main() {
//! let html = r#"
//! <!doctype html>
//! <html lang="en">
//! <head>
//! <meta charset="utf-8">
//! <title>Html parser</title>
//! </head>
//! <body>
//! <h1 id="a" class="b c">Hello world</h1>
//! </h1> <!-- comments & dangling elements are ignored -->
//! </body>
//! </html>"#;
//!
//! let dom = Dom::parse(html).unwrap();
//! println!("{}", dom.to_json_pretty().unwrap());
//! println!("{}", dom);
//! }
//! ```
//!
//! Parse html fragment and print as json & formatted fragment
//! ```rust
//! use lithtml::Dom;
//!
//! fn main() {
//! let html = "<div id=cat />";
//! let dom = Dom::parse(html).unwrap();
//! println!("{}", dom.to_json_pretty().unwrap());
//! println!("{}", dom);
//! }
//! ```
//!
//! Print to json
//! ```rust
//! use lithtml::{Dom, Result};
//!
//! fn main() -> Result<()> {
//! let html = "<div id=cat />";
//! let json = Dom::parse(html)?.to_json_pretty()?;
//! println!("{}", Dom::parse(html)?);
//! Ok(())
//! }
//! ```
//!
//! Create a dom manually and print it
//! ```rust
//! use lithtml::{Dom, Node, Result};
//!
//! fn main() -> Result<()> {
//! let mut dom = Dom::new();
//! dom.children.push(Node::new_comment("Welcome to the test"));
//! dom.children.push(Node::parse_json(
//! r#"{
//! "name": "div",
//! "variant": "normal",
//! "children": [
//! {
//! "name": "h1",
//! "variant": "normal",
//! "children": [
//! "Tjena världen!"
//! ]
//! },
//! {
//! "name": "p",
//! "variant": "normal",
//! "children": [
//! "Tänkte bara informera om att Sverige är bättre än Finland i ishockey."
//! ]
//! }
//! ]
//! }"#
//! )?);
//! dom.children.append(&mut Node::parse(
//! r#"<div>Testing</div><p>Multiple elements from node</p>"#,
//! )?);
//!
//! println!("{}", dom);
//! Ok(())
//! }
//! ```
use Rule;
pub use crate;
pub use crateNode;
pub use crateFormattingOptions;
pub use crateDom;
pub use crateDomVariant;
pub use crateError;
pub use crateResult;