#html #parser #editor #dom

html_editor

Pure, simple and elegant HTML parser and editor

7 releases (4 breaking)

0.5.2 Aug 21, 2022
0.5.1 Apr 27, 2022
0.4.0 Mar 19, 2022
0.3.0 Jan 28, 2022
0.1.0 Jan 1, 2022

#25 in Text editors

Download history 296/week @ 2022-12-03 350/week @ 2022-12-10 178/week @ 2022-12-17 45/week @ 2022-12-24 239/week @ 2022-12-31 313/week @ 2023-01-07 342/week @ 2023-01-14 393/week @ 2023-01-21 575/week @ 2023-01-28 450/week @ 2023-02-04 586/week @ 2023-02-11 878/week @ 2023-02-18 811/week @ 2023-02-25 499/week @ 2023-03-04 525/week @ 2023-03-11 313/week @ 2023-03-18

2,311 downloads per month
Used in 3 crates (2 directly)

MIT license

42KB
805 lines

crate-badge License check-badge

HTML Editor

Pure and simple HTML parser and editor.

Examples

Parse HTML segment/document

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>");

Query an element / elements by selector

// let html = r#"..."#
let nodes = parse(html)?;
let selector: Selector = Selector::from(".box");
let element: Element = nodes.query(&selector).unwrap();
let elements: Vec<Element> = nodes.query_all(&selector);

Edit the HTML

// 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();

You can find more examples in the documentation.

Changelog

See in CHANGELOG.md

No runtime deps