pub struct Html {
pub quirks_mode: QuirksMode,
pub tree: Tree<Node>,
}
Expand description
An HTML tree.
Parsing does not fail hard. Instead, the quirks_mode
is set and errors are added to the
errors
field. The tree
will still be populated as best as possible.
Implements the TreeSink
trait from the fast_html5ever
crate, which allows HTML to be parsed.
Fields§
§quirks_mode: QuirksMode
The quirks mode.
tree: Tree<Node>
The node tree.
Implementations§
Source§impl Html
impl Html
Sourcepub fn new_document() -> Html
pub fn new_document() -> Html
Creates an empty HTML document.
Sourcepub fn new_fragment() -> Html
pub fn new_fragment() -> Html
Creates an empty HTML fragment.
Sourcepub fn parse_document(document: &str) -> Html
pub fn parse_document(document: &str) -> Html
Parses a string of HTML as a document.
This is a convenience method for the following:
use fast_html5ever::driver::{self, ParseOpts};
use accessibility_scraper::Html;
use tendril::TendrilSink;
let parser = driver::parse_document(Html::new_document(), ParseOpts::default());
let html = parser.one(document);
Sourcepub fn parse_fragment(fragment: &str) -> Html
pub fn parse_fragment(fragment: &str) -> Html
Parses a string of HTML as a fragment.
Sourcepub fn select<'a, 'b>(&'a self, selector: &'b Selector) -> Select<'a, 'b>
pub fn select<'a, 'b>(&'a self, selector: &'b Selector) -> Select<'a, 'b>
Returns an iterator over elements matching a selector.
Sourcepub fn root_element(&self) -> ElementRef<'_>
pub fn root_element(&self) -> ElementRef<'_>
Returns the root <html>
element.
Trait Implementations§
Source§impl Serialize for Html
impl Serialize for Html
Source§fn serialize<S>(
&self,
serializer: &mut S,
traversal_scope: TraversalScope,
) -> Result<(), Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: &mut S,
traversal_scope: TraversalScope,
) -> Result<(), Error>where
S: Serializer,
Take the serializer and call its methods to serialize this type. The type will dictate
which methods are called and with what parameters.
Source§impl TreeSink for Html
Note: does not support the <template>
element.
impl TreeSink for Html
Note: does not support the <template>
element.
Source§type Handle = NodeId
type Handle = NodeId
Handle
is a reference to a DOM node. The tree builder requires
that a Handle
implements Clone
to get another reference to
the same node.Source§fn parse_error(&mut self, msg: Cow<'static, str>)
fn parse_error(&mut self, msg: Cow<'static, str>)
Signal a parse error.
Source§fn set_quirks_mode(&mut self, mode: QuirksMode)
fn set_quirks_mode(&mut self, mode: QuirksMode)
Set the document’s quirks mode.
Source§fn same_node(
&self,
x: &<Html as TreeSink>::Handle,
y: &<Html as TreeSink>::Handle,
) -> bool
fn same_node( &self, x: &<Html as TreeSink>::Handle, y: &<Html as TreeSink>::Handle, ) -> bool
Do two handles refer to the same node?
Source§fn elem_name(&self, target: &<Html as TreeSink>::Handle) -> ExpandedName<'_>
fn elem_name(&self, target: &<Html as TreeSink>::Handle) -> ExpandedName<'_>
What is the name of this element? Read more
Source§fn create_element(
&mut self,
name: QualName,
attrs: Vec<Attribute>,
_flags: ElementFlags,
) -> <Html as TreeSink>::Handle
fn create_element( &mut self, name: QualName, attrs: Vec<Attribute>, _flags: ElementFlags, ) -> <Html as TreeSink>::Handle
Create an element. Read more
Source§fn create_comment(&mut self, _text: Tendril<UTF8>)
fn create_comment(&mut self, _text: Tendril<UTF8>)
Create a comment node.
Source§fn append_doctype_to_document(
&mut self,
name: Tendril<UTF8>,
public_id: Tendril<UTF8>,
system_id: Tendril<UTF8>,
)
fn append_doctype_to_document( &mut self, name: Tendril<UTF8>, public_id: Tendril<UTF8>, system_id: Tendril<UTF8>, )
Append a
DOCTYPE
element to the Document
node.Source§fn append(
&mut self,
parent: &<Html as TreeSink>::Handle,
child: NodeOrText<<Html as TreeSink>::Handle>,
)
fn append( &mut self, parent: &<Html as TreeSink>::Handle, child: NodeOrText<<Html as TreeSink>::Handle>, )
Append a node as the last child of the given node. If this would
produce adjacent sibling text nodes, it should concatenate the text
instead. Read more
Source§fn append_before_sibling(
&mut self,
sibling: &<Html as TreeSink>::Handle,
new_node: NodeOrText<<Html as TreeSink>::Handle>,
)
fn append_before_sibling( &mut self, sibling: &<Html as TreeSink>::Handle, new_node: NodeOrText<<Html as TreeSink>::Handle>, )
Append a node as the sibling immediately before the given node. Read more
Source§fn remove_from_parent(&mut self, target: &<Html as TreeSink>::Handle)
fn remove_from_parent(&mut self, target: &<Html as TreeSink>::Handle)
Detach the given node from its parent.
Source§fn reparent_children(
&mut self,
node: &<Html as TreeSink>::Handle,
new_parent: &<Html as TreeSink>::Handle,
)
fn reparent_children( &mut self, node: &<Html as TreeSink>::Handle, new_parent: &<Html as TreeSink>::Handle, )
Remove all the children from node and append them to new_parent.
Source§fn add_attrs_if_missing(
&mut self,
target: &<Html as TreeSink>::Handle,
attrs: Vec<Attribute>,
)
fn add_attrs_if_missing( &mut self, target: &<Html as TreeSink>::Handle, attrs: Vec<Attribute>, )
Add each attribute to the given element, if no attribute with that name
already exists. The tree builder promises this will never be called
with something else than an element.
Source§fn get_template_contents(
&mut self,
target: &<Html as TreeSink>::Handle,
) -> <Html as TreeSink>::Handle
fn get_template_contents( &mut self, target: &<Html as TreeSink>::Handle, ) -> <Html as TreeSink>::Handle
Get a handle to a template’s template contents. The tree builder
promises this will never be called with something else than
a template element.
Source§fn mark_script_already_started(&mut self, _node: &<Html as TreeSink>::Handle)
fn mark_script_already_started(&mut self, _node: &<Html as TreeSink>::Handle)
Mark a HTML
<script>
as “already started”.Source§fn create_pi(
&mut self,
target: Tendril<UTF8>,
data: Tendril<UTF8>,
) -> <Html as TreeSink>::Handle
fn create_pi( &mut self, target: Tendril<UTF8>, data: Tendril<UTF8>, ) -> <Html as TreeSink>::Handle
Create a Processing Instruction node.
Source§fn append_based_on_parent_node(
&mut self,
element: &<Html as TreeSink>::Handle,
prev_element: &<Html as TreeSink>::Handle,
child: NodeOrText<<Html as TreeSink>::Handle>,
)
fn append_based_on_parent_node( &mut self, element: &<Html as TreeSink>::Handle, prev_element: &<Html as TreeSink>::Handle, child: NodeOrText<<Html as TreeSink>::Handle>, )
When the insertion point is decided by the existence of a parent node of the
element, we consider both possibilities and send the element which will be used
if a parent node exists, along with the element to be used if there isn’t one.
Source§fn pop(&mut self, _node: &Self::Handle)
fn pop(&mut self, _node: &Self::Handle)
Indicate that a node was popped off the stack of open elements.
Source§fn associate_with_form(
&mut self,
_target: &Self::Handle,
_form: &Self::Handle,
_nodes: (&Self::Handle, Option<&Self::Handle>),
)
fn associate_with_form( &mut self, _target: &Self::Handle, _form: &Self::Handle, _nodes: (&Self::Handle, Option<&Self::Handle>), )
Associate the given form-associatable element with the form element
Source§fn is_mathml_annotation_xml_integration_point(
&self,
_handle: &Self::Handle,
) -> bool
fn is_mathml_annotation_xml_integration_point( &self, _handle: &Self::Handle, ) -> bool
Returns true if the adjusted current node is an HTML integration point
and the token is a start tag.
Source§fn set_current_line(&mut self, _line_number: u64)
fn set_current_line(&mut self, _line_number: u64)
Called whenever the line number changes.
Source§fn complete_script(&mut self, _node: &Self::Handle) -> NextParserState
fn complete_script(&mut self, _node: &Self::Handle) -> NextParserState
Indicate that a
script
element is complete.impl Eq for Html
impl StructuralPartialEq for Html
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to
key
and return true
if they are equal.Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
Converts
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more