Skip to main content

Document

Struct Document 

Source
pub struct Document { /* private fields */ }
Expand description

A parsed HTML document backed by an arena.

Provides access to the root node and convenience methods for querying the DOM tree.

Implementations§

Source§

impl Document

Source

pub fn root(&self) -> NodeRef<'_>

Get a reference to the root node.

Source

pub fn get(&self, id: NodeId) -> NodeRef<'_>

Get a node by its id.

§Panics

Panics if id is out of bounds.

Source

pub fn arena(&self) -> &Arena

Get the underlying arena (for advanced usage).

Source

pub fn to_html(&self) -> String

Serialize the entire document back to an HTML string.

This produces the outer HTML of the root node, which includes all children with proper entity escaping for text and attribute values.

§Example
use fhp_tree::parse;

let doc = parse("<p>Hello &amp; world</p>").unwrap();
let html = doc.to_html();
assert!(html.contains("&amp;"));
Source

pub fn node_count(&self) -> usize

Total number of nodes in the document.

Source

pub fn root_id(&self) -> NodeId

Root node id.

Auto Trait Implementations§

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> 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.