Struct visdom::Vis [−][src]
Vis: Entry struct of the mesdoc
’s api.
Examples
use visdom::Vis; use std::error::Error; fn main()-> Result<(), Box<dyn Error>>{ let html = r##" <!doctype html> <html> <head> <meta charset="utf-8" /> </head> <body> <nav id="header"> <ul> <li>Hello,</li> <li>Vis</li> <li>Dom</li> </ul> </nav> </body> </html> "##; let doc = Vis::load(html)?; // All useful css selectors are well supported. let header = doc.find("#header"); let list_items = header.children("ul > li"); assert_eq!(list_items.length(), 3); assert_eq!(list_items.text(), "Hello,VisDom"); let second_child = list_items.filter(":nth-child(2)"); assert_eq!(second_child.text(), "Vis"); // Easy to operate the nodes. let mut fourth_child = Vis::load("<li>!</li>")?; let mut parent = list_items.parent(""); assert_eq!(parent.length(), 1); fourth_child.append_to(&mut parent); let mut cur_list_items = header.children("ul > li"); assert_eq!(cur_list_items.length(), 4); assert_eq!(cur_list_items.text(), "Hello,VisDom!"); // Powerful api for operate text nodes // use append_text and prepend_text to change text let mut texts = cur_list_items.texts(0); texts.for_each(|_index, text_node|{ text_node.prepend_text("["); text_node.append_text("]"); true }); assert_eq!(cur_list_items.text(), "[Hello,][Vis][Dom][!]"); // use set_text to change text texts.for_each(|_index, text_node|{ text_node.set_text("@"); true }); assert_eq!(cur_list_items.text(), "@@@@"); // use set_html to mix content texts.for_each(|_index, text_node|{ let orig_text = text_node.text(); let replace_html = format!("<span>{}</span><b>!</b>", orig_text); // Be careful that now the text_node is destoryed by `set_html` text_node.set_html(&replace_html); true }); assert_eq!(cur_list_items.children("b").length(), 4); assert_eq!(cur_list_items.text(), "@!@!@!@!"); Ok(()) }
Implementations
impl Vis
[src]
pub fn load_options(
html: &str,
options: ParseOptions
) -> Result<Elements<'_>, Box<dyn Error>>
[src]
html: &str,
options: ParseOptions
) -> Result<Elements<'_>, Box<dyn Error>>
load the html with options, get an elements collection
pub fn load_options_catch(
html: &str,
options: ParseOptions,
handle: IErrorHandle
) -> Elements<'_>
[src]
html: &str,
options: ParseOptions,
handle: IErrorHandle
) -> Elements<'_>
load the html with options, and catch the errors
pub fn load(html: &str) -> Result<Elements<'_>, Box<dyn Error>>
[src]
load the html into elements
pub fn load_catch(html: &str, handle: IErrorHandle) -> Elements<'_>
[src]
load the html, and catch the errors
pub fn dom<'b>(ele: &BoxDynElement<'_>) -> Elements<'b>
[src]
return an elements collection from an BoxDynElement
Auto Trait Implementations
impl RefUnwindSafe for Vis
impl Send for Vis
impl Sync for Vis
impl Unpin for Vis
impl UnwindSafe for Vis
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,