@@ -18,7 +18,7 @@ impl<'a> MarkdownRenderer<'a> {
18
18
/// Per `readme_to_html`, `base_url` is the base URL prepended to any
19
19
/// relative links in the input document. See that function for more detail.
20
20
fn new ( base_url : Option < & ' a str > ) -> MarkdownRenderer < ' a > {
21
- let tags = [
21
+ let tags = hashset ( & [
22
22
"a" ,
23
23
"b" ,
24
24
"blockquote" ,
@@ -58,30 +58,15 @@ impl<'a> MarkdownRenderer<'a> {
58
58
"ul" ,
59
59
"hr" ,
60
60
"span" ,
61
- ]
62
- . iter ( )
63
- . cloned ( )
64
- . collect ( ) ;
65
- let tag_attributes = [
66
- ( "a" , [ "href" , "id" , "target" ] . iter ( ) . cloned ( ) . collect ( ) ) ,
67
- (
68
- "img" ,
69
- [ "width" , "height" , "src" , "alt" , "align" ]
70
- . iter ( )
71
- . cloned ( )
72
- . collect ( ) ,
73
- ) ,
74
- (
75
- "input" ,
76
- [ "checked" , "disabled" , "type" ] . iter ( ) . cloned ( ) . collect ( ) ,
77
- ) ,
78
- ]
79
- . iter ( )
80
- . cloned ( )
81
- . collect ( ) ;
82
- let allowed_classes = [ (
61
+ ] ) ;
62
+ let tag_attributes = hashmap ( & [
63
+ ( "a" , hashset ( & [ "href" , "id" , "target" ] ) ) ,
64
+ ( "img" , hashset ( & [ "width" , "height" , "src" , "alt" , "align" ] ) ) ,
65
+ ( "input" , hashset ( & [ "checked" , "disabled" , "type" ] ) ) ,
66
+ ] ) ;
67
+ let allowed_classes = hashmap ( & [ (
83
68
"code" ,
84
- [
69
+ hashset ( & [
85
70
"language-bash" ,
86
71
"language-clike" ,
87
72
"language-glsl" ,
@@ -96,14 +81,8 @@ impl<'a> MarkdownRenderer<'a> {
96
81
"language-scss" ,
97
82
"language-sql" ,
98
83
"yaml" ,
99
- ]
100
- . iter ( )
101
- . cloned ( )
102
- . collect ( ) ,
103
- ) ]
104
- . iter ( )
105
- . cloned ( )
106
- . collect ( ) ;
84
+ ] ) ,
85
+ ) ] ) ;
107
86
108
87
let sanitizer_base_url = base_url. map ( ToString :: to_string) ;
109
88
@@ -255,6 +234,23 @@ pub fn readme_to_html(text: &str, filename: &str, base_url: Option<&str>) -> Car
255
234
Ok ( encode_minimal ( text) . replace ( "\n " , "<br>\n " ) )
256
235
}
257
236
237
+ /// Helper function to build a new `HashSet` from the items slice.
238
+ fn hashset < T > ( items : & [ T ] ) -> std:: collections:: HashSet < T >
239
+ where
240
+ T : Clone + Eq + std:: hash:: Hash ,
241
+ {
242
+ items. iter ( ) . cloned ( ) . collect ( )
243
+ }
244
+
245
+ /// Helper function to build a new `HashMap` from a slice of key-value pairs.
246
+ fn hashmap < K , V > ( items : & [ ( K , V ) ] ) -> std:: collections:: HashMap < K , V >
247
+ where
248
+ K : Clone + Eq + std:: hash:: Hash ,
249
+ V : Clone ,
250
+ {
251
+ items. iter ( ) . cloned ( ) . collect ( )
252
+ }
253
+
258
254
#[ cfg( test) ]
259
255
mod tests {
260
256
use super :: * ;
0 commit comments