pub struct Html { /* private fields */ }
Expand description
An HTML fragment.
To get the serialized HTML, use its Display
implementation. Due to the fact that the HTML is
parsed, note that malformed HTML and comments will be stripped from the output.
Implementations§
source§impl Html
impl Html
sourcepub fn parse(string: &str) -> Self
pub fn parse(string: &str) -> Self
Construct a new Html
by parsing the given string.
This is infallible, any error encountered while parsing the HTML is logged with
tracing::debug!
.
sourcepub fn sanitize(&mut self)
pub fn sanitize(&mut self)
Sanitize this HTML according to the Matrix specification.
This is equivalent to calling Self::sanitize_with()
with a config
value of
SanitizerConfig::compat().remove_reply_fallback()
.
sourcepub fn sanitize_with(&mut self, config: SanitizerConfig)
pub fn sanitize_with(&mut self, config: SanitizerConfig)
Sanitize this HTML according to the given configuration.
Trait Implementations§
source§impl TreeSink for Html
impl TreeSink for Html
§type Handle = usize
type Handle = usize
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 finish(self) -> Self::Output
fn finish(self) -> Self::Output
Consume this sink and return the overall result of parsing. Read more
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 get_document(&mut self) -> Self::Handle
fn get_document(&mut self) -> Self::Handle
Get a handle to the
Document
node.source§fn elem_name<'a>(&'a self, target: &'a Self::Handle) -> ExpandedName<'a>
fn elem_name<'a>(&'a self, target: &'a Self::Handle) -> ExpandedName<'a>
What is the name of this element? Read more
source§fn create_element(
&mut self,
name: QualName,
attrs: Vec<Attribute>,
_flags: ElementFlags
) -> Self::Handle
fn create_element( &mut self, name: QualName, attrs: Vec<Attribute>, _flags: ElementFlags ) -> Self::Handle
Create an element. Read more
source§fn create_comment(&mut self, _text: StrTendril) -> Self::Handle
fn create_comment(&mut self, _text: StrTendril) -> Self::Handle
Create a comment node.
source§fn create_pi(&mut self, _target: StrTendril, _data: StrTendril) -> Self::Handle
fn create_pi(&mut self, _target: StrTendril, _data: StrTendril) -> Self::Handle
Create a Processing Instruction node.
source§fn append(&mut self, parent: &Self::Handle, child: NodeOrText<Self::Handle>)
fn append(&mut self, parent: &Self::Handle, child: NodeOrText<Self::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_based_on_parent_node(
&mut self,
element: &Self::Handle,
prev_element: &Self::Handle,
child: NodeOrText<Self::Handle>
)
fn append_based_on_parent_node( &mut self, element: &Self::Handle, prev_element: &Self::Handle, child: NodeOrText<Self::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 append_doctype_to_document(
&mut self,
_name: StrTendril,
_public_id: StrTendril,
_system_id: StrTendril
)
fn append_doctype_to_document( &mut self, _name: StrTendril, _public_id: StrTendril, _system_id: StrTendril )
Append a
DOCTYPE
element to the Document
node.source§fn get_template_contents(&mut self, target: &Self::Handle) -> Self::Handle
fn get_template_contents(&mut self, target: &Self::Handle) -> Self::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 same_node(&self, x: &Self::Handle, y: &Self::Handle) -> bool
fn same_node(&self, x: &Self::Handle, y: &Self::Handle) -> bool
Do two handles refer to the same node?
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 append_before_sibling(
&mut self,
sibling: &Self::Handle,
new_node: NodeOrText<Self::Handle>
)
fn append_before_sibling( &mut self, sibling: &Self::Handle, new_node: NodeOrText<Self::Handle> )
Append a node as the sibling immediately before the given node. Read more
source§fn add_attrs_if_missing(&mut self, target: &Self::Handle, attrs: Vec<Attribute>)
fn add_attrs_if_missing(&mut self, target: &Self::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 remove_from_parent(&mut self, target: &Self::Handle)
fn remove_from_parent(&mut self, target: &Self::Handle)
Detach the given node from its parent.
source§fn reparent_children(&mut self, node: &Self::Handle, new_parent: &Self::Handle)
fn reparent_children(&mut self, node: &Self::Handle, new_parent: &Self::Handle)
Remove all the children from node and append them to new_parent.
§fn mark_script_already_started(&mut self, _node: &Self::Handle)
fn mark_script_already_started(&mut self, _node: &Self::Handle)
Mark a HTML
<script>
as “already started”.§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.
§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
§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.
§fn set_current_line(&mut self, _line_number: u64)
fn set_current_line(&mut self, _line_number: u64)
Called whenever the line number changes.
§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.Auto Trait Implementations§
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