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(&self)
pub fn sanitize(&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(&self, config: &SanitizerConfig)
pub fn sanitize_with(&self, config: &SanitizerConfig)
Sanitize this HTML according to the given configuration.
Sourcepub fn has_children(&self) -> bool
pub fn has_children(&self) -> bool
Whether the root node of the HTML has children.
Sourcepub fn first_child(&self) -> Option<NodeRef>
pub fn first_child(&self) -> Option<NodeRef>
The first child node of the root node of the HTML.
Returns None
if the root node has no children.
Sourcepub fn last_child(&self) -> Option<NodeRef>
pub fn last_child(&self) -> Option<NodeRef>
The last child node of the root node of the HTML .
Returns None
if the root node has no children.
Trait Implementations§
Source§impl Serialize for Html
impl Serialize for Html
Source§fn serialize<S>(
&self,
serializer: &mut S,
traversal_scope: TraversalScope,
) -> Result<()>where
S: Serializer,
fn serialize<S>(
&self,
serializer: &mut S,
traversal_scope: TraversalScope,
) -> Result<()>where
S: Serializer,
Source§impl TreeSink for Html
impl TreeSink for Html
Source§type Handle = NodeRef
type Handle = NodeRef
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.type ElemName<'a> = ExpandedName<'a>
Source§fn finish(self) -> Self::Output
fn finish(self) -> Self::Output
Source§fn parse_error(&self, msg: Cow<'static, str>)
fn parse_error(&self, msg: Cow<'static, str>)
Source§fn get_document(&self) -> Self::Handle
fn get_document(&self) -> Self::Handle
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>
Source§fn create_element(
&self,
name: QualName,
attrs: Vec<Attribute>,
_flags: ElementFlags,
) -> Self::Handle
fn create_element( &self, name: QualName, attrs: Vec<Attribute>, _flags: ElementFlags, ) -> Self::Handle
Source§fn create_comment(&self, _text: StrTendril) -> Self::Handle
fn create_comment(&self, _text: StrTendril) -> Self::Handle
Source§fn create_pi(&self, _target: StrTendril, _data: StrTendril) -> Self::Handle
fn create_pi(&self, _target: StrTendril, _data: StrTendril) -> Self::Handle
Source§fn append(&self, parent: &Self::Handle, child: NodeOrText<Self::Handle>)
fn append(&self, parent: &Self::Handle, child: NodeOrText<Self::Handle>)
Source§fn append_based_on_parent_node(
&self,
element: &Self::Handle,
prev_element: &Self::Handle,
child: NodeOrText<Self::Handle>,
)
fn append_based_on_parent_node( &self, element: &Self::Handle, prev_element: &Self::Handle, child: NodeOrText<Self::Handle>, )
Source§fn append_doctype_to_document(
&self,
_name: StrTendril,
_public_id: StrTendril,
_system_id: StrTendril,
)
fn append_doctype_to_document( &self, _name: StrTendril, _public_id: StrTendril, _system_id: StrTendril, )
DOCTYPE
element to the Document
node.Source§fn get_template_contents(&self, target: &Self::Handle) -> Self::Handle
fn get_template_contents(&self, target: &Self::Handle) -> Self::Handle
Source§fn same_node(&self, x: &Self::Handle, y: &Self::Handle) -> bool
fn same_node(&self, x: &Self::Handle, y: &Self::Handle) -> bool
Source§fn set_quirks_mode(&self, _mode: QuirksMode)
fn set_quirks_mode(&self, _mode: QuirksMode)
Source§fn append_before_sibling(
&self,
sibling: &Self::Handle,
new_node: NodeOrText<Self::Handle>,
)
fn append_before_sibling( &self, sibling: &Self::Handle, new_node: NodeOrText<Self::Handle>, )
Source§fn add_attrs_if_missing(&self, target: &Self::Handle, attrs: Vec<Attribute>)
fn add_attrs_if_missing(&self, target: &Self::Handle, attrs: Vec<Attribute>)
Source§fn remove_from_parent(&self, target: &Self::Handle)
fn remove_from_parent(&self, target: &Self::Handle)
Source§fn reparent_children(&self, node: &Self::Handle, new_parent: &Self::Handle)
fn reparent_children(&self, node: &Self::Handle, new_parent: &Self::Handle)
Source§fn mark_script_already_started(&self, _node: &Self::Handle)
fn mark_script_already_started(&self, _node: &Self::Handle)
<script>
as “already started”.Source§fn pop(&self, _node: &Self::Handle)
fn pop(&self, _node: &Self::Handle)
Source§fn associate_with_form(
&self,
_target: &Self::Handle,
_form: &Self::Handle,
_nodes: (&Self::Handle, Option<&Self::Handle>),
)
fn associate_with_form( &self, _target: &Self::Handle, _form: &Self::Handle, _nodes: (&Self::Handle, Option<&Self::Handle>), )
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
Source§fn set_current_line(&self, _line_number: u64)
fn set_current_line(&self, _line_number: u64)
Source§fn complete_script(&self, _node: &Self::Handle) -> NextParserState
fn complete_script(&self, _node: &Self::Handle) -> NextParserState
script
element is complete.