10
10
extern crate html5ever;
11
11
extern crate typed_arena;
12
12
13
- use html5ever:: { parse_document , QualName , Attribute , ExpandedName } ;
14
- use html5ever:: tendril:: { TendrilSink , StrTendril } ;
15
- use html5ever:: interface :: tree_builder :: { TreeSink , QuirksMode , NodeOrText , ElementFlags } ;
13
+ use html5ever:: interface :: tree_builder :: { ElementFlags , NodeOrText , QuirksMode , TreeSink } ;
14
+ use html5ever:: tendril:: { StrTendril , TendrilSink } ;
15
+ use html5ever:: { parse_document , Attribute , ExpandedName , QualName } ;
16
16
use std:: borrow:: Cow ;
17
17
use std:: cell:: { Cell , RefCell } ;
18
18
use std:: collections:: HashSet ;
@@ -32,7 +32,9 @@ fn html5ever_parse_slice_into_arena<'a>(bytes: &[u8], arena: Arena<'a>) -> Ref<'
32
32
document : arena. alloc ( Node :: new ( NodeData :: Document ) ) ,
33
33
quirks_mode : QuirksMode :: NoQuirks ,
34
34
} ;
35
- parse_document ( sink, Default :: default ( ) ) . from_utf8 ( ) . one ( bytes)
35
+ parse_document ( sink, Default :: default ( ) )
36
+ . from_utf8 ( )
37
+ . one ( bytes)
36
38
}
37
39
38
40
type Arena < ' arena > = & ' arena typed_arena:: Arena < Node < ' arena > > ;
@@ -131,7 +133,10 @@ impl<'arena> Node<'arena> {
131
133
new_sibling. next_sibling . set ( Some ( self ) ) ;
132
134
if let Some ( previous_sibling) = self . previous_sibling . take ( ) {
133
135
new_sibling. previous_sibling . set ( Some ( previous_sibling) ) ;
134
- debug_assert ! ( ptr:: eq:: <Node >( previous_sibling. next_sibling. get( ) . unwrap( ) , self ) ) ;
136
+ debug_assert ! ( ptr:: eq:: <Node >(
137
+ previous_sibling. next_sibling. get( ) . unwrap( ) ,
138
+ self
139
+ ) ) ;
135
140
previous_sibling. next_sibling . set ( Some ( new_sibling) ) ;
136
141
} else if let Some ( parent) = self . parent . get ( ) {
137
142
debug_assert ! ( ptr:: eq:: <Node >( parent. first_child. get( ) . unwrap( ) , self ) ) ;
@@ -147,19 +152,26 @@ impl<'arena> Sink<'arena> {
147
152
}
148
153
149
154
fn append_common < P , A > ( & self , child : NodeOrText < Ref < ' arena > > , previous : P , append : A )
150
- where P : FnOnce ( ) -> Option < Ref < ' arena > > ,
151
- A : FnOnce ( Ref < ' arena > ) ,
155
+ where
156
+ P : FnOnce ( ) -> Option < Ref < ' arena > > ,
157
+ A : FnOnce ( Ref < ' arena > ) ,
152
158
{
153
159
let new_node = match child {
154
160
NodeOrText :: AppendText ( text) => {
155
161
// Append to an existing Text node if we have one.
156
- if let Some ( & Node { data : NodeData :: Text { ref contents } , .. } ) = previous ( ) {
162
+ if let Some ( & Node {
163
+ data : NodeData :: Text { ref contents } ,
164
+ ..
165
+ } ) = previous ( )
166
+ {
157
167
contents. borrow_mut ( ) . push_tendril ( & text) ;
158
- return
168
+ return ;
159
169
}
160
- self . new_node ( NodeData :: Text { contents : RefCell :: new ( text) } )
161
- }
162
- NodeOrText :: AppendNode ( node) => node
170
+ self . new_node ( NodeData :: Text {
171
+ contents : RefCell :: new ( text) ,
172
+ } )
173
+ } ,
174
+ NodeOrText :: AppendNode ( node) => node,
163
175
} ;
164
176
165
177
append ( new_node)
@@ -196,22 +208,35 @@ impl<'arena> TreeSink for Sink<'arena> {
196
208
}
197
209
198
210
fn get_template_contents ( & mut self , target : & Ref < ' arena > ) -> Ref < ' arena > {
199
- if let NodeData :: Element { template_contents : Some ( ref contents) , .. } = target. data {
211
+ if let NodeData :: Element {
212
+ template_contents : Some ( ref contents) ,
213
+ ..
214
+ } = target. data
215
+ {
200
216
contents
201
217
} else {
202
218
panic ! ( "not a template element!" )
203
219
}
204
220
}
205
221
206
222
fn is_mathml_annotation_xml_integration_point ( & self , target : & Ref < ' arena > ) -> bool {
207
- if let NodeData :: Element { mathml_annotation_xml_integration_point, .. } = target. data {
223
+ if let NodeData :: Element {
224
+ mathml_annotation_xml_integration_point,
225
+ ..
226
+ } = target. data
227
+ {
208
228
mathml_annotation_xml_integration_point
209
229
} else {
210
230
panic ! ( "not an element!" )
211
231
}
212
232
}
213
233
214
- fn create_element ( & mut self , name : QualName , attrs : Vec < Attribute > , flags : ElementFlags ) -> Ref < ' arena > {
234
+ fn create_element (
235
+ & mut self ,
236
+ name : QualName ,
237
+ attrs : Vec < Attribute > ,
238
+ flags : ElementFlags ,
239
+ ) -> Ref < ' arena > {
215
240
self . new_node ( NodeData :: Element {
216
241
name : name,
217
242
attrs : RefCell :: new ( attrs) ,
@@ -221,7 +246,6 @@ impl<'arena> TreeSink for Sink<'arena> {
221
246
None
222
247
} ,
223
248
mathml_annotation_xml_integration_point : flags. mathml_annotation_xml_integration_point ,
224
-
225
249
} )
226
250
}
227
251
@@ -230,42 +254,51 @@ impl<'arena> TreeSink for Sink<'arena> {
230
254
}
231
255
232
256
fn create_pi ( & mut self , target : StrTendril , data : StrTendril ) -> Ref < ' arena > {
233
- self . new_node ( NodeData :: ProcessingInstruction { target : target, contents : data } )
257
+ self . new_node ( NodeData :: ProcessingInstruction {
258
+ target : target,
259
+ contents : data,
260
+ } )
234
261
}
235
262
236
263
fn append ( & mut self , parent : & Ref < ' arena > , child : NodeOrText < Ref < ' arena > > ) {
237
264
self . append_common (
238
265
child,
239
266
|| parent. last_child . get ( ) ,
240
- |new_node| parent. append ( new_node)
267
+ |new_node| parent. append ( new_node) ,
241
268
)
242
269
}
243
270
244
271
fn append_before_sibling ( & mut self , sibling : & Ref < ' arena > , child : NodeOrText < Ref < ' arena > > ) {
245
272
self . append_common (
246
273
child,
247
274
|| sibling. previous_sibling . get ( ) ,
248
- |new_node| sibling. insert_before ( new_node)
275
+ |new_node| sibling. insert_before ( new_node) ,
249
276
)
250
277
}
251
278
252
- fn append_based_on_parent_node ( & mut self , element : & Ref < ' arena > ,
253
- prev_element : & Ref < ' arena > , child : NodeOrText < Ref < ' arena > > ) {
279
+ fn append_based_on_parent_node (
280
+ & mut self ,
281
+ element : & Ref < ' arena > ,
282
+ prev_element : & Ref < ' arena > ,
283
+ child : NodeOrText < Ref < ' arena > > ,
284
+ ) {
254
285
if element. parent . get ( ) . is_some ( ) {
255
286
self . append_before_sibling ( element, child)
256
287
} else {
257
288
self . append ( prev_element, child)
258
289
}
259
290
}
260
291
261
- fn append_doctype_to_document ( & mut self ,
262
- name : StrTendril ,
263
- public_id : StrTendril ,
264
- system_id : StrTendril ) {
292
+ fn append_doctype_to_document (
293
+ & mut self ,
294
+ name : StrTendril ,
295
+ public_id : StrTendril ,
296
+ system_id : StrTendril ,
297
+ ) {
265
298
self . document . append ( self . new_node ( NodeData :: Doctype {
266
299
name : name,
267
300
public_id : public_id,
268
- system_id : system_id
301
+ system_id : system_id,
269
302
} ) )
270
303
}
271
304
@@ -276,10 +309,15 @@ impl<'arena> TreeSink for Sink<'arena> {
276
309
panic ! ( "not an element" )
277
310
} ;
278
311
279
- let existing_names = existing. iter ( ) . map ( |e| e. name . clone ( ) ) . collect :: < HashSet < _ > > ( ) ;
280
- existing. extend ( attrs. into_iter ( ) . filter ( |attr| {
281
- !existing_names. contains ( & attr. name )
282
- } ) ) ;
312
+ let existing_names = existing
313
+ . iter ( )
314
+ . map ( |e| e. name . clone ( ) )
315
+ . collect :: < HashSet < _ > > ( ) ;
316
+ existing. extend (
317
+ attrs
318
+ . into_iter ( )
319
+ . filter ( |attr| !existing_names. contains ( & attr. name ) ) ,
320
+ ) ;
283
321
}
284
322
285
323
fn remove_from_parent ( & mut self , target : & Ref < ' arena > ) {
0 commit comments