Skip to main content

HTMLTag

Struct HTMLTag 

Source
pub struct HTMLTag<'a> { /* private fields */ }
Expand description

Represents a single HTML element

Implementations§

Source§

impl<'a> HTMLTag<'a>

Source

pub fn children(&self) -> Children<'a, '_>

Returns a wrapper around the children of this HTML tag

Source

pub fn children_mut(&mut self) -> ChildrenMut<'a, '_>

Returns a mutable wrapper around the children of this HTML tag.

Source

pub fn name(&self) -> &Bytes<'a>

Returns the name of this HTML tag

Source

pub fn name_mut(&mut self) -> &mut Bytes<'a>

Returns a mutable reference to the name of this HTML tag

Source

pub fn attributes(&self) -> &Attributes<'a>

Returns attributes of this HTML tag

Source

pub fn attributes_mut(&mut self) -> &mut Attributes<'a>

Returns a mutable reference to the attributes of this HTML tag

Source

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.

Source

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.

Source

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.

Source

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>");
Source

pub fn find_node<F>(&self, parser: &Parser<'a>, f: &mut F) -> Option<NodeHandle>
where F: FnMut(&Node<'a>) -> bool,

Calls the given closure with each tag as parameter

The closure must return a boolean, indicating whether it should stop iterating Returning true will break the loop

Trait Implementations§

Source§

impl<'a> Clone for HTMLTag<'a>

Source§

fn clone(&self) -> HTMLTag<'a>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<'a> Debug for HTMLTag<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'a, 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> QueryIterable<'a, MAX_NODES, MAX_STACK, MAX_ROOTS, MAX_IDS, MAX_CLASSES, MAX_SELECTOR_NODES> for HTMLTag<'a>

Source§

fn get<'b>( &'b self, parser: &'b Parser<'a, MAX_NODES, MAX_STACK, MAX_ROOTS, MAX_IDS, MAX_CLASSES, MAX_SELECTOR_NODES>, index: usize, ) -> Option<(&'b Node<'a>, NodeHandle)>

Gets a node at a specific index
Source§

fn len( &self, parser: &Parser<'a, MAX_NODES, MAX_STACK, MAX_ROOTS, MAX_IDS, MAX_CLASSES, MAX_SELECTOR_NODES>, ) -> usize

Gets or computes the length (number of nodes)
Source§

fn start(&self) -> Option<InnerNodeHandle>

Gets the starting index

Auto Trait Implementations§

§

impl<'a> !Send for HTMLTag<'a>

§

impl<'a> !Sync for HTMLTag<'a>

§

impl<'a> Freeze for HTMLTag<'a>

§

impl<'a> RefUnwindSafe for HTMLTag<'a>

§

impl<'a> Unpin for HTMLTag<'a>

§

impl<'a> UnsafeUnpin for HTMLTag<'a>

§

impl<'a> UnwindSafe for HTMLTag<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.