Trait html5ever::tree_builder::TreeSink
source · pub trait TreeSink {
type Handle: Clone;
type Output;
type ElemName<'a>: ElemName
where Self: 'a;
Show 23 methods
// Required methods
fn finish(self) -> Self::Output;
fn parse_error(&self, msg: Cow<'static, str>);
fn get_document(&self) -> Self::Handle;
fn elem_name<'a>(&'a self, target: &'a Self::Handle) -> Self::ElemName<'a>;
fn create_element(
&self,
name: QualName,
attrs: Vec<Attribute>,
flags: ElementFlags,
) -> Self::Handle;
fn create_comment(&self, text: Tendril<UTF8>) -> Self::Handle;
fn create_pi(
&self,
target: Tendril<UTF8>,
data: Tendril<UTF8>,
) -> Self::Handle;
fn append(&self, parent: &Self::Handle, child: NodeOrText<Self::Handle>);
fn append_based_on_parent_node(
&self,
element: &Self::Handle,
prev_element: &Self::Handle,
child: NodeOrText<Self::Handle>,
);
fn append_doctype_to_document(
&self,
name: Tendril<UTF8>,
public_id: Tendril<UTF8>,
system_id: Tendril<UTF8>,
);
fn get_template_contents(&self, target: &Self::Handle) -> Self::Handle;
fn same_node(&self, x: &Self::Handle, y: &Self::Handle) -> bool;
fn set_quirks_mode(&self, mode: QuirksMode);
fn append_before_sibling(
&self,
sibling: &Self::Handle,
new_node: NodeOrText<Self::Handle>,
);
fn add_attrs_if_missing(&self, target: &Self::Handle, attrs: Vec<Attribute>);
fn remove_from_parent(&self, target: &Self::Handle);
fn reparent_children(&self, node: &Self::Handle, new_parent: &Self::Handle);
// Provided methods
fn mark_script_already_started(&self, _node: &Self::Handle) { ... }
fn pop(&self, _node: &Self::Handle) { ... }
fn associate_with_form(
&self,
_target: &Self::Handle,
_form: &Self::Handle,
_nodes: (&Self::Handle, Option<&Self::Handle>),
) { ... }
fn is_mathml_annotation_xml_integration_point(
&self,
_handle: &Self::Handle,
) -> bool { ... }
fn set_current_line(&self, _line_number: u64) { ... }
fn complete_script(&self, _node: &Self::Handle) -> NextParserState { ... }
}
Expand description
Methods a parser can use to create the DOM. The DOM provider implements this trait.
Having this as a trait potentially allows multiple implementations of the DOM to be used with the same parser.
Required Associated Types§
sourcetype Handle: Clone
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.
sourcetype Output
type Output
The overall result of parsing.
This should default to Self, but default associated types are not stable yet. rust-lang/rust#29661
type ElemName<'a>: ElemName where Self: 'a
Required Methods§
sourcefn finish(self) -> Self::Output
fn finish(self) -> Self::Output
Consume this sink and return the overall result of parsing.
TODO:This should default to fn finish(self) -> Self::Output { self }
,
but default associated types are not stable yet.
rust-lang/rust#29661
sourcefn parse_error(&self, msg: Cow<'static, str>)
fn parse_error(&self, msg: Cow<'static, str>)
Signal a parse error.
sourcefn get_document(&self) -> Self::Handle
fn get_document(&self) -> Self::Handle
Get a handle to the Document
node.
sourcefn elem_name<'a>(&'a self, target: &'a Self::Handle) -> Self::ElemName<'a>
fn elem_name<'a>(&'a self, target: &'a Self::Handle) -> Self::ElemName<'a>
What is the name of this element?
Should never be called on a non-element node;
feel free to panic!
.
sourcefn 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
Create an element.
When creating a template element (name.ns.expanded() == expanded_name!(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.
See the template element in the whatwg spec.
sourcefn create_comment(&self, text: Tendril<UTF8>) -> Self::Handle
fn create_comment(&self, text: Tendril<UTF8>) -> Self::Handle
Create a comment node.
sourcefn create_pi(&self, target: Tendril<UTF8>, data: Tendril<UTF8>) -> Self::Handle
fn create_pi(&self, target: Tendril<UTF8>, data: Tendril<UTF8>) -> Self::Handle
Create a Processing Instruction node.
sourcefn append(&self, parent: &Self::Handle, child: NodeOrText<Self::Handle>)
fn append(&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.
sourcefn 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>, )
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.
sourcefn append_doctype_to_document(
&self,
name: Tendril<UTF8>,
public_id: Tendril<UTF8>,
system_id: Tendril<UTF8>,
)
fn append_doctype_to_document( &self, name: Tendril<UTF8>, public_id: Tendril<UTF8>, system_id: Tendril<UTF8>, )
Append a DOCTYPE
element to the Document
node.
sourcefn get_template_contents(&self, target: &Self::Handle) -> Self::Handle
fn get_template_contents(&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.
sourcefn 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?
sourcefn set_quirks_mode(&self, mode: QuirksMode)
fn set_quirks_mode(&self, mode: QuirksMode)
Set the document’s quirks mode.
sourcefn 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>, )
Append a node as the sibling immediately before the given 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.
sourcefn add_attrs_if_missing(&self, target: &Self::Handle, attrs: Vec<Attribute>)
fn add_attrs_if_missing(&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.
sourcefn remove_from_parent(&self, target: &Self::Handle)
fn remove_from_parent(&self, target: &Self::Handle)
Detach the given node from its parent.
sourcefn reparent_children(&self, node: &Self::Handle, new_parent: &Self::Handle)
fn reparent_children(&self, node: &Self::Handle, new_parent: &Self::Handle)
Remove all the children from node and append them to new_parent.
Provided Methods§
sourcefn mark_script_already_started(&self, _node: &Self::Handle)
fn mark_script_already_started(&self, _node: &Self::Handle)
Mark a HTML <script>
as “already started”.
sourcefn pop(&self, _node: &Self::Handle)
fn pop(&self, _node: &Self::Handle)
Indicate that a node was popped off the stack of open elements.
sourcefn 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>), )
Associate the given form-associatable element with the form element
sourcefn 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.
sourcefn set_current_line(&self, _line_number: u64)
fn set_current_line(&self, _line_number: u64)
Called whenever the line number changes.
sourcefn complete_script(&self, _node: &Self::Handle) -> NextParserState
fn complete_script(&self, _node: &Self::Handle) -> NextParserState
Indicate that a script
element is complete.