Crate html_editor

source ·
Expand description

html_editor is a simple html parser and editor.

Quick Start:

use html_editor::operation::*;
use html_editor::{parse, Node};

// You can create DOM nodes by parsing html string.
let html = r#"
    <!doctype html>
    <html>
        <head>
        </head>
        <body>
        </body>
    </html>
"#;
let mut dom = parse(html).unwrap();

// Or you can create a node by some built-in methods like below.
let app: Node = Node::new_element("div", vec![("id", "app")], vec![]);

// Here shows how to edit the nodes and turn it back to html.
let html = dom
    .remove_by(&Selector::from("head"))
    .insert_to(&Selector::from("body"), app)
    .trim()
    .html();

assert_eq!(
    html,
    r#"<!DOCTYPE html><html><body><div id="app"></div></body></html>"#
);

Modules

Structs

Enums

Functions

  • Parse the html string and return a Vector of Node.
  • Alternative for parse() with fault tolerance feature.