@@ -5,14 +5,15 @@ use regex::Regex;
55use wasm_bindgen:: { JsCast , JsValue } ;
66use web_sys:: { Comment , Element , Node , Text } ;
77
8- use crate :: util:: { named_node_map_to_hashmap, node_list_to_vec} ;
8+ use crate :: util:: { named_node_map_to_hashmap, named_node_map_to_vec , node_list_to_vec} ;
99
1010fn escape_html ( text : String ) -> String {
1111 text. replace ( '<' , "<" ) . replace ( '>' , ">" )
1212}
1313
1414fn print_props (
15- attributes : HashMap < String , String > ,
15+ keys : Vec < String > ,
16+ props : HashMap < String , String > ,
1617 config : & Config ,
1718 indentation : String ,
1819 depth : usize ,
@@ -21,25 +22,26 @@ fn print_props(
2122) -> String {
2223 let indentation_next = format ! ( "{}{}" , indentation, config. indent) ;
2324
24- attributes
25- . into_iter ( )
26- . map ( |( key , value) | {
27- let printed = printer (
28- & JsValue :: from_str ( & value) ,
29- config,
30- indentation_next. clone ( ) ,
31- depth,
32- refs. clone ( ) ,
33- None ,
34- ) ;
25+ keys . into_iter ( )
26+ . filter_map ( |key| {
27+ props . get ( & key ) . map ( |value| {
28+ let printed = printer (
29+ & JsValue :: from_str ( value) ,
30+ config,
31+ indentation_next. clone ( ) ,
32+ depth,
33+ refs. clone ( ) ,
34+ None ,
35+ ) ;
3536
36- format ! (
37- "{}{}{}={}" ,
38- config. spacing_inner,
39- indentation,
40- config. colors. prop. paint( & key) ,
41- config. colors. value. paint( & printed)
42- )
37+ format ! (
38+ "{}{}{}={}" ,
39+ config. spacing_inner,
40+ indentation,
41+ config. colors. prop. paint( & key) ,
42+ config. colors. value. paint( & printed)
43+ )
44+ } )
4345 } )
4446 . collect :: < Vec < _ > > ( )
4547 . join ( "" )
@@ -67,7 +69,7 @@ fn print_children(
6769
6870 if printed_child. is_empty ( ) && child. node_type ( ) != Node :: TEXT_NODE {
6971 // A plugin serialized this Node to '' meaning we should ignore it.
70- "" . into ( )
72+ "" . to_owned ( )
7173 } else {
7274 format ! ( "{}{}{}" , config. spacing_outer, indentation, printed_child)
7375 }
@@ -99,7 +101,7 @@ fn print_element(
99101 "<{}{}{}>" ,
100102 r#type,
101103 if printed_props. is_empty( ) {
102- "" . into ( )
104+ "" . to_owned ( )
103105 } else {
104106 format!(
105107 "{}{}{}{}{}" ,
@@ -112,9 +114,9 @@ fn print_element(
112114 } ,
113115 if printed_children. is_empty( ) {
114116 if !printed_props. is_empty( ) && !config. min {
115- "/" . into ( )
117+ "/" . to_owned ( )
116118 } else {
117- " /" . into ( )
119+ " /" . to_owned ( )
118120 }
119121 } else {
120122 format!(
@@ -207,7 +209,7 @@ impl Plugin for DomElementFilter {
207209 }
208210
209211 let r#type = if node_is_fragment ( node) {
210- "DocumentFragment" . into ( )
212+ "DocumentFragment" . to_owned ( )
211213 } else {
212214 node. unchecked_ref :: < Element > ( ) . tag_name ( ) . to_lowercase ( )
213215 } ;
@@ -220,6 +222,19 @@ impl Plugin for DomElementFilter {
220222 print_element (
221223 r#type,
222224 print_props (
225+ if node_is_fragment ( node) {
226+ vec ! [ ]
227+ } else {
228+ let mut keys =
229+ named_node_map_to_vec ( node. unchecked_ref :: < Element > ( ) . attributes ( ) )
230+ . into_iter ( )
231+ . map ( |attr| attr. name ( ) )
232+ . collect :: < Vec < _ > > ( ) ;
233+
234+ keys. sort ( ) ;
235+
236+ keys
237+ } ,
223238 if node_is_fragment ( node) {
224239 HashMap :: new ( )
225240 } else {
0 commit comments