Trait html5ever::tree_builder::interface::TreeSink
[−]
[src]
pub trait TreeSink { type Output; type Handle: Clone; fn finish(self) -> Self::Output; fn parse_error(&mut self, msg: Cow<'static, str>); fn get_document(&mut self) -> Self::Handle; fn get_template_contents(&mut self, target: Self::Handle) -> Self::Handle; fn same_node(&self, x: Self::Handle, y: Self::Handle) -> bool; fn elem_name(&self, target: Self::Handle) -> QualName; fn set_quirks_mode(&mut self, mode: QuirksMode); fn create_element(&mut self, name: QualName, attrs: Vec<Attribute>) -> Self::Handle; fn create_comment(&mut self, text: StrTendril) -> Self::Handle; fn append(&mut self, parent: Self::Handle, child: NodeOrText<Self::Handle>); fn append_before_sibling(&mut self, sibling: Self::Handle, new_node: NodeOrText<Self::Handle>) -> Result<(), NodeOrText<Self::Handle>>; fn append_doctype_to_document(&mut self, name: StrTendril, public_id: StrTendril, system_id: StrTendril); fn add_attrs_if_missing(&mut self, target: Self::Handle, attrs: Vec<Attribute>); fn remove_from_parent(&mut self, target: Self::Handle); fn reparent_children(&mut self, node: Self::Handle, new_parent: Self::Handle); fn mark_script_already_started(&mut self, node: Self::Handle); fn complete_script(&mut self, _node: Self::Handle) -> NextParserState { ... } fn is_mathml_annotation_xml_integration_point(&self, handle: Self::Handle) -> bool { ... } }
Types which can process tree modifications from the tree builder.
Associated Types
type Output
The overall result of parsing.
This should default to Self, but default associated types are not stable yet. (https://github.com/rust-lang/rust/issues/29661)
type Handle: Clone
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.
Required Methods
fn finish(self) -> Self::Output
Consume this sink and return the overall result of parsing.
This should default to fn finish(self) -> Self::Output { self }
,
but default associated types are not stable yet.
(https://github.com/rust-lang/rust/issues/29661)
fn parse_error(&mut self, msg: Cow<'static, str>)
Signal a parse error.
fn get_document(&mut self) -> Self::Handle
Get a handle to the Document
node.
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.
fn same_node(&self, x: Self::Handle, y: Self::Handle) -> bool
Do two handles refer to the same node?
fn elem_name(&self, target: Self::Handle) -> QualName
What is the name of this element?
Should never be called on a non-element node;
feel free to panic!
.
fn set_quirks_mode(&mut self, mode: QuirksMode)
Set the document's quirks mode.
fn create_element(&mut self, name: QualName, attrs: Vec<Attribute>) -> Self::Handle
Create an element.
When creating a template element (name == qualname!(html, "template")
),
an associated document fragment called the "template contents" should
also be created. Later calls to self.get_template_contents() with that
given element return it.
https://html.spec.whatwg.org/multipage/#htmltemplateelement
fn create_comment(&mut self, text: StrTendril) -> Self::Handle
Create a comment node.
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.
The child node will not already have a parent.
fn append_before_sibling(&mut self, sibling: Self::Handle, new_node: NodeOrText<Self::Handle>) -> Result<(), NodeOrText<Self::Handle>>
Append a node as the sibling immediately before the given node. If that node has no parent, do nothing and return Err(new_node).
The tree builder promises that sibling
is not a text node. However its
old previous sibling, which would become the new node's previous sibling,
could be a text node. If the new node is also a text node, the two should
be merged, as in the behavior of append
.
NB: new_node
may have an old parent, from which it should be removed.
fn append_doctype_to_document(&mut self, name: StrTendril, public_id: StrTendril, system_id: StrTendril)
Append a DOCTYPE
element to the Document
node.
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.
fn remove_from_parent(&mut self, target: Self::Handle)
Detach the given node from its parent.
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)
Mark a HTML <script>
element as "already started".
Provided Methods
fn complete_script(&mut self, _node: Self::Handle) -> NextParserState
Indicate that a <script>
element is complete.
fn is_mathml_annotation_xml_integration_point(&self, handle: Self::Handle) -> bool
Implementors
impl TreeSink for RcDom