Crates.io | html_editor |
lib.rs | html_editor |
version | 0.7.0 |
source | src |
created_at | 2022-01-01 13:30:23.604364 |
updated_at | 2023-11-14 06:08:19.781669 |
description | Pure and simple HTML parser and editor. |
homepage | https://github.com/lomirus/html_editor |
repository | https://github.com/lomirus/html_editor |
max_upload_size | |
id | 506155 |
size | 152,737 |
Pure and simple HTML parser and editor.
let document: Vec<Node> = parse("<!doctype html><html><head></head><body></body></html>")?;
println!("{:#?}", document);
Output:
[
Doctype(
Html,
),
Element {
name: "html",
attrs: {},
children: [
Element {
name: "head",
attrs: {},
children: [],
},
Element {
name: "body",
attrs: {},
children: [],
},
],
},
]
You can also use try_parse
to parse the html which contains tolerable errors
let document: Vec<Node> = try_parse("<div><span>Ipsum</div>");
// let html = r#"..."#
let nodes: Vec<Node> = parse(html)?;
let selector: Selector = Selector::from(".box");
let element: Option<Element> = nodes.query(&selector);
let elements: Vec<Element> = nodes.query_all(&selector);
// let html = r#"..."#
let a: String = parse(html)?.trim().html();
let b: String = parse(html)?.insert_to(&selector, node).html();
let c: String = parse(html)?.remove_by(&selector).html();
let d: String = parse(html)?.replace_with(&selector, |el| Node::Comment(el.html())).html();
You can find more examples in the documentation.
See in CHANGELOG.md