#[non_exhaustive]pub enum Html {
Comment(String),
Doctype {
name: String,
attr: Option<String>,
},
Empty,
Tag {
tag: Tag,
child: Box<Html>,
},
Text(String),
Vec(Box<[Html]>),
}
Expand description
Dom tree structure to represent the parsed html.
This tree represents the whole parsed HTML. To create an Html
from a
string, use the Html::parse
function.
§Examples
use html_filter::prelude::*;
let _html: Html = Html::parse(
r#"<nav>
<!-- Navigation menu -->
<ul>
<li href="first">First link</li>
<li href="second">Second link</li>
<li href="third">Third link</li>
</ul>
</nav>"#,
)
.unwrap();
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
Comment(String)
Doctype
Fields
This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
Empty
Empty html tree
Corresponds to an empty string
Tag
Fields
This variant is marked as non-exhaustive
Non-exhaustive enum variants could have additional fields added in future. Therefore, non-exhaustive enum variants cannot be constructed in external crates and cannot be matched against.
Text(String)
Vec(Box<[Html]>)
List of nodes
§Examples
In a<strong>b
, the node is a vector, with Html::Text
a
,
Html::Tag
strong
Html::Text
b
.
Implementations§
Source§impl Html
impl Html
Sourcepub fn to_filtered(&self, filter: &Filter) -> Self
pub fn to_filtered(&self, filter: &Filter) -> Self
Filters html based on a defined filter.
Equivalent of Html::filter
when data is not owned.
Sourcepub fn to_found(&self, filter: &Filter) -> Self
pub fn to_found(&self, filter: &Filter) -> Self
Finds an html node based on a defined filter.
Equivalent of Html::find
when data is not owned.
Source§impl Html
impl Html
Sourcepub fn parse(html: &str) -> Result<Self, String>
pub fn parse(html: &str) -> Result<Self, String>
Parses an HTML string into a Dom tree.
§Errors
This function returns an error when the input HTML’s syntax is invalid.
§Examples
use html_filter::prelude::*;
let html: &str = r#"
<!DOCTYPE html>
<html lang="en">
<head>
<title>Html sample</title>
</head>
<body>
<p>This is an html sample.</p>
</body>
</html>
"#;
let tree: Html = Html::parse(html).expect("Invalid HTML");
assert!(format!("{tree}") == html);
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Html
impl RefUnwindSafe for Html
impl Send for Html
impl Sync for Html
impl Unpin for Html
impl UnwindSafe for Html
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more