diff --git a/examples/noop-tree-builder.rs b/examples/noop-tree-builder.rs index c4336bb1..b2d18a9e 100644 --- a/examples/noop-tree-builder.rs +++ b/examples/noop-tree-builder.rs @@ -7,6 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![cfg_attr(feature = "unstable", feature(plugin))] +#![cfg_attr(feature = "unstable", plugin(string_cache_plugin))] + +#[macro_use] extern crate string_cache; extern crate tendril; extern crate html5ever; @@ -31,7 +35,7 @@ struct Sink { impl Sink { fn get_id(&mut self) -> usize { let id = self.next_id; - self.next_id += 1; + self.next_id += 2; id } } @@ -43,6 +47,14 @@ impl TreeSink for Sink { 0 } + fn get_template_contents(&self, target: usize) -> usize { + if let Some(&qualname!(HTML, template)) = self.names.get(&target) { + target + 1 + } else { + panic!("not a template element") + } + } + fn same_node(&self, x: usize, y: usize) -> bool { x == y } diff --git a/examples/print-rcdom.rs b/examples/print-rcdom.rs index 115794af..f4106204 100644 --- a/examples/print-rcdom.rs +++ b/examples/print-rcdom.rs @@ -44,7 +44,7 @@ fn walk(indent: usize, handle: Handle) { Comment(ref text) => println!("", escape_default(text)), - Element(ref name, ref attrs) => { + Element(ref name, _, ref attrs) => { assert!(name.ns == ns!(html)); print!("<{}", name.local); for attr in attrs.iter() { diff --git a/examples/print-tree-actions.rs b/examples/print-tree-actions.rs index 9eebcc14..baf41e49 100644 --- a/examples/print-tree-actions.rs +++ b/examples/print-tree-actions.rs @@ -7,6 +7,10 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. +#![cfg_attr(feature = "unstable", feature(plugin))] +#![cfg_attr(feature = "unstable", plugin(string_cache_plugin))] + +#[macro_use] extern crate string_cache; extern crate tendril; extern crate html5ever; @@ -31,7 +35,7 @@ struct Sink { impl Sink { fn get_id(&mut self) -> usize { let id = self.next_id; - self.next_id += 1; + self.next_id += 2; id } } @@ -47,6 +51,14 @@ impl TreeSink for Sink { 0 } + fn get_template_contents(&self, target: usize) -> usize { + if let Some(&qualname!(HTML, template)) = self.names.get(&target) { + target + 1 + } else { + panic!("not a template element") + } + } + fn set_quirks_mode(&mut self, mode: QuirksMode) { println!("Set quirks mode to {:?}", mode); } diff --git a/src/rcdom.rs b/src/rcdom.rs index 667c75ae..c1fe5577 100644 --- a/src/rcdom.rs +++ b/src/rcdom.rs @@ -32,8 +32,21 @@ use serialize::TraversalScope; use serialize::TraversalScope::{IncludeNode, ChildrenOnly}; use driver::ParseResult; +pub use self::ElementEnum::{Normal, Script, Template}; pub use self::NodeEnum::{Document, Doctype, Text, Comment, Element}; +/// The different kinds of elements in the DOM. +#[derive(Debug)] +pub enum ElementEnum { + Normal, + /// A script element and its "already started" flag. + /// https://html.spec.whatwg.org/multipage/#already-started + Script(bool), + /// A template element and its template contents. + /// https://html.spec.whatwg.org/multipage/#template-contents + Template(Handle), +} + /// The different kinds of nodes in the DOM. #[derive(Debug)] pub enum NodeEnum { @@ -50,19 +63,15 @@ pub enum NodeEnum { Comment(StrTendril), /// An element with attributes. - Element(QualName, Vec), + Element(QualName, ElementEnum, Vec), } /// A DOM node. +#[derive(Debug)] pub struct Node { pub node: NodeEnum, pub parent: Option, pub children: Vec, - - /// The "script already started" flag. - /// - /// Not meaningful for nodes other than HTML `