pub enum Node {
    Element {
        name: String,
        attrs: Vec<(String, String)>,
        children: Vec<Node>,
    },
    Text(String),
    Comment(String),
    Doctype,
}
Expand description

Basic node of dom

Variants

Element

Fields

name: String
attrs: Vec<(String, String)>
children: Vec<Node>

Text(String)

Comment(String)

Doctype

Implementations

Check if it is an element node.

use html_editor::Node;
 
assert_eq!(Node::new_element("div", vec![("id", "app")], vec![]).is_element(), true);
assert_eq!(Node::Text("Lorem Ipsum".to_string()).is_element(), false);

Convert the node into an element.

Note: The program will panic if it fails to convert. So take care to use this method unless you are sure.

use html_editor::{Node, Element};
 
let a: Node = Node::new_element("div", vec![("id", "app")], vec![]);
let a: Element = a.into_element();
 
let b: Node = Node::Text("hello".to_string());
// This will panic at 'Text("hello") is not an element'
// let b: Element = a.into_element();

Create a new element node.

use html_editor::Node;
 
let node: Node = Node::new_element(
    "h1", 
    vec![("class", "title")],
    vec![
        Node::Text("Hello, world!".to_string()),
    ]
);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Convert the object to html string. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.