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