@@ -8,7 +8,8 @@ use super::{
88} ;
99use crate :: { html:: DocumentStyleMap , InlineError } ;
1010use html5ever:: local_name;
11- use std:: { io:: Write , iter:: successors} ;
11+ use selectors:: NthIndexCache ;
12+ use std:: { cell:: RefCell , fmt, fmt:: Formatter , io:: Write , iter:: successors} ;
1213
1314/// HTML document representation.
1415///
@@ -35,18 +36,28 @@ use std::{io::Write, iter::successors};
3536///
3637/// Each Node within the `Document` is interconnected with its siblings, and has a parent-child
3738/// relationship with its descendants.
38- #[ derive( Debug ) ]
3939pub ( crate ) struct Document {
4040 pub ( crate ) nodes : Vec < Node > ,
41- /// Ids of Element nodes.
42- pub ( crate ) elements : Vec < NodeId > ,
41+ /// Ids of Element nodes & caches for their nth index selectors .
42+ pub ( crate ) elements : Vec < ( NodeId , RefCell < NthIndexCache > ) > ,
4343 /// Ids of `style` nodes.
4444 styles : Vec < NodeId > ,
4545 /// Ids of `link` nodes, specifically those with the `rel` attribute value set as `stylesheet`.
4646 /// They represent the locations (URLs) of all linked stylesheet resources in the document.
4747 linked_stylesheets : Vec < NodeId > ,
4848}
4949
50+ impl fmt:: Debug for Document {
51+ fn fmt ( & self , f : & mut Formatter < ' _ > ) -> fmt:: Result {
52+ f. debug_struct ( "Document" )
53+ . field ( "nodes" , & self . nodes )
54+ . field ( "styles" , & self . styles )
55+ . field ( "linked_stylesheets" , & self . linked_stylesheets )
56+ . finish_non_exhaustive ( ) ?;
57+ Ok ( ( ) )
58+ }
59+ }
60+
5061impl Document {
5162 pub ( crate ) fn parse_with_options ( bytes : & [ u8 ] , preallocate_node_capacity : usize ) -> Document {
5263 parser:: parse_with_options ( bytes, preallocate_node_capacity)
@@ -111,7 +122,7 @@ impl Document {
111122
112123 #[ inline]
113124 pub ( super ) fn push_element_id ( & mut self , node : NodeId ) {
114- self . elements . push ( node) ;
125+ self . elements . push ( ( node, RefCell :: default ( ) ) ) ;
115126 }
116127
117128 /// Detach a node from its siblings and its parent.
0 commit comments