@@ -4,7 +4,6 @@ use std::collections::HashMap;
44
55pub use gosub_shared:: node:: NodeId ;
66
7- /// Map of attributes for a html element (a href, src, data-*, etc)
87#[ derive( Debug , Clone ) ]
98pub struct AttrMap {
109 attributes : HashMap < String , String > ,
@@ -30,11 +29,6 @@ impl AttrMap {
3029 pub fn set ( & mut self , key : & str , value : & str ) {
3130 self . attributes . insert ( key. to_string ( ) , value. to_string ( ) ) ;
3231 }
33-
34- #[ allow( unused) ]
35- pub fn all ( & self ) -> & HashMap < String , String > {
36- & self . attributes
37- }
3832}
3933
4034impl std:: fmt:: Display for AttrMap {
@@ -49,28 +43,19 @@ impl std::fmt::Display for AttrMap {
4943 }
5044}
5145
52- /// Data for a html element (tag name, attributes, styles etc)
5346#[ derive( Clone , Debug ) ]
5447pub struct ElementData {
5548 pub tag_name : String ,
5649 pub attributes : AttrMap ,
57- #[ allow( unused) ]
58- pub self_closing : bool ,
5950 /// Own CSS properties for this element (only explicitly-set values; no inheritance).
6051 pub styles : NodeStyle ,
6152}
6253
6354impl ElementData {
64- pub fn new (
65- tag_name : String ,
66- attributes : Option < AttrMap > ,
67- is_self_closing : bool ,
68- styles : Option < NodeStyle > ,
69- ) -> ElementData {
55+ pub fn new ( tag_name : String , attributes : Option < AttrMap > , styles : Option < NodeStyle > ) -> ElementData {
7056 ElementData {
7157 tag_name,
7258 attributes : attributes. unwrap_or_default ( ) ,
73- self_closing : is_self_closing,
7459 styles : styles. unwrap_or_default ( ) ,
7560 }
7661 }
@@ -79,21 +64,10 @@ impl ElementData {
7964 self . styles . get_own ( key)
8065 }
8166
82- #[ allow( unused) ]
8367 pub fn get_attribute ( & self , key : & str ) -> Option < & String > {
8468 self . attributes . get ( key)
8569 }
8670
87- #[ allow( unused) ]
88- pub fn set_attribute ( & mut self , key : & str , value : & str ) {
89- self . attributes . set ( key, value) ;
90- }
91-
92- #[ allow( unused) ]
93- pub fn is_self_closing ( & self ) -> bool {
94- self . self_closing
95- }
96-
9771 pub fn is_inline_element ( & self ) -> bool {
9872 matches ! (
9973 self . get_style( & StyleProperty :: Display ) ,
@@ -154,10 +128,9 @@ impl Node {
154128 match & self . node_type {
155129 NodeType :: Element ( data) => match data. get_style ( & StyleProperty :: Display ) {
156130 Some ( Value :: Display ( Display :: Inline ) ) => true ,
157- // When no display is explicitly set, use the HTML element's intrinsic type.
158- // CSS initial value is `inline`, but UA stylesheets set `block` for most
159- // HTML structural elements. Defaulting unknown elements to inline here
160- // would incorrectly group <li>, <h2>, <div> etc. into inline flows.
131+ // The CSS initial value is `inline`, but UA stylesheets make most structural
132+ // elements `block` - defaulting to inline would group <li>, <h2>, <div> etc.
133+ // into inline flows, so fall back to the tag's intrinsic type.
161134 None => is_intrinsically_inline ( & data. tag_name ) ,
162135 _ => false ,
163136 } ,
@@ -181,10 +154,8 @@ impl Node {
181154 }
182155}
183156
184- /// Returns true if `tag` is an HTML element that is inline by spec when no CSS is applied.
185- /// Block-level elements (`div`, `p`, `h1`–`h6`, `li`, `section`, etc.) return false so that
186- /// missing `display` in NodeStyle (e.g. from a UA-stylesheet gap) does not accidentally put
187- /// them into an inline formatting context.
157+ /// Inline-by-spec HTML elements. Block-level tags return false so a missing `display` (e.g. a
158+ /// UA-stylesheet gap) never drops them into an inline formatting context.
188159fn is_intrinsically_inline ( tag : & str ) -> bool {
189160 matches ! (
190161 tag. cow_to_ascii_lowercase( ) . as_ref( ) ,
0 commit comments