pub struct HTMLTag<'a> { /* private fields */ }Expand description
Represents a single HTML element
Implementations§
Source§impl<'a> HTMLTag<'a>
impl<'a> HTMLTag<'a>
Sourcepub fn children(&self) -> Children<'a, '_>
pub fn children(&self) -> Children<'a, '_>
Returns a wrapper around the children of this HTML tag
Sourcepub fn children_mut(&mut self) -> ChildrenMut<'a, '_>
pub fn children_mut(&mut self) -> ChildrenMut<'a, '_>
Returns a mutable wrapper around the children of this HTML tag.
Sourcepub fn name_mut(&mut self) -> &mut Bytes<'a>
pub fn name_mut(&mut self) -> &mut Bytes<'a>
Returns a mutable reference to the name of this HTML tag
Sourcepub fn attributes(&self) -> &Attributes<'a>
pub fn attributes(&self) -> &Attributes<'a>
Returns attributes of this HTML tag
Sourcepub fn attributes_mut(&mut self) -> &mut Attributes<'a>
pub fn attributes_mut(&mut self) -> &mut Attributes<'a>
Returns a mutable reference to the attributes of this HTML tag
Sourcepub fn write_outer_html<W: Write, const MAX_NODES: usize, const MAX_STACK: usize, const MAX_ROOTS: usize, const MAX_IDS: usize, const MAX_CLASSES: usize, const MAX_SELECTOR_NODES: usize>(
&self,
parser: &Parser<'a, MAX_NODES, MAX_STACK, MAX_ROOTS, MAX_IDS, MAX_CLASSES, MAX_SELECTOR_NODES>,
dest: &mut W,
) -> Result
pub fn write_outer_html<W: Write, const MAX_NODES: usize, const MAX_STACK: usize, const MAX_ROOTS: usize, const MAX_IDS: usize, const MAX_CLASSES: usize, const MAX_SELECTOR_NODES: usize>( &self, parser: &Parser<'a, MAX_NODES, MAX_STACK, MAX_ROOTS, MAX_IDS, MAX_CLASSES, MAX_SELECTOR_NODES>, dest: &mut W, ) -> Result
Writes the contained markup to a formatter without allocating.
Sourcepub fn write_inner_html<W: Write, const MAX_NODES: usize, const MAX_STACK: usize, const MAX_ROOTS: usize, const MAX_IDS: usize, const MAX_CLASSES: usize, const MAX_SELECTOR_NODES: usize>(
&self,
parser: &Parser<'a, MAX_NODES, MAX_STACK, MAX_ROOTS, MAX_IDS, MAX_CLASSES, MAX_SELECTOR_NODES>,
dest: &mut W,
) -> Result
pub fn write_inner_html<W: Write, const MAX_NODES: usize, const MAX_STACK: usize, const MAX_ROOTS: usize, const MAX_IDS: usize, const MAX_CLASSES: usize, const MAX_SELECTOR_NODES: usize>( &self, parser: &Parser<'a, MAX_NODES, MAX_STACK, MAX_ROOTS, MAX_IDS, MAX_CLASSES, MAX_SELECTOR_NODES>, dest: &mut W, ) -> Result
Writes the contained child markup to a formatter without allocating.
Sourcepub fn raw(&self) -> &Bytes<'a>
pub fn raw(&self) -> &Bytes<'a>
Returns the raw HTML of this tag.
This is a cheaper version of HTMLTag::inner_html if you never mutate any nodes.
Note: Mutating this tag does not re-compute the HTML representation of this tag. This simply returns a reference to the substring.
Sourcepub fn boundaries<const MAX_NODES: usize, const MAX_STACK: usize, const MAX_ROOTS: usize, const MAX_IDS: usize, const MAX_CLASSES: usize, const MAX_SELECTOR_NODES: usize>(
&self,
parser: &Parser<'a, MAX_NODES, MAX_STACK, MAX_ROOTS, MAX_IDS, MAX_CLASSES, MAX_SELECTOR_NODES>,
) -> (usize, usize)
pub fn boundaries<const MAX_NODES: usize, const MAX_STACK: usize, const MAX_ROOTS: usize, const MAX_IDS: usize, const MAX_CLASSES: usize, const MAX_SELECTOR_NODES: usize>( &self, parser: &Parser<'a, MAX_NODES, MAX_STACK, MAX_ROOTS, MAX_IDS, MAX_CLASSES, MAX_SELECTOR_NODES>, ) -> (usize, usize)
Returns the boundaries/position (start, end) of this HTML tag in the source string.
§Example
let source = "<p><span>hello</span></p>";
#[cfg(feature = "std")]
let dom = tl::parse(source, Default::default()).unwrap();
#[cfg(not(feature = "std"))]
let dom = tl::parse::<8, 8, 8, 4, 4, 4>(source, Default::default()).unwrap();
let parser = dom.parser();
let span = dom.nodes().iter().filter_map(|n| n.as_tag()).find(|n| n.name() == "span").unwrap();
let (start, end) = span.boundaries(parser);
assert_eq!((start, end), (3, 20));
assert_eq!(&source[start..=end], "<span>hello</span>");