pub trait Editable {
    fn trim(&mut self) -> &mut Self;
fn insert_to(&mut self, selector: &Selector, target: Node) -> &mut Self;
fn remove_by(&mut self, selector: &Selector) -> &mut Self; }
Expand description

Used to insert or remove elements by Selector, and trim the dom.

Required methods

Remove all empty text nodes from self.

use html_editor::parse;
use html_editor::prelude::*;

let html = r#"
    <!DOCTYPE html>
    <html>
        <head></head>
        <body></body>
    </html>"#;

let html = parse(html).unwrap().trim().html();
assert_eq!(html, r#"<!DOCTYPE html><html><head></head><body></body></html>"#)

Insert node as the last child to all elements that matches the selector.

use html_editor::{parse, Node, Selector};
use html_editor::prelude::*;

let html = r#"<div><span>Ok</span></div>"#;

let selector = Selector::from("div");
let html = parse(html)
    .unwrap()
    .insert_to(&selector, Node::new_element(
        "span",
        vec![],
        vec![Node::Text("Cancel".to_string())]
    ))
    .html();
assert_eq!(html, r#"<div><span>Ok</span><span>Cancel</span></div>"#)

Remove all elements that matches the selector.

use html_editor::{parse, Selector};
use html_editor::prelude::*;

let html = r#"
<div>
    <div class="recommend"></div>
    <div class="results"></div>
    <div class="ad"></div>
</div>"#;

let selector = Selector::from(".ad");
let html = parse(html).unwrap().remove_by(&selector).html();
assert_eq!(html, r#"
<div>
    <div class="recommend"></div>
    <div class="results"></div>
    
</div>"#)

Implementations on Foreign Types

Implementors