@@ -15,7 +15,7 @@ struct MarkdownRenderer<'a> {
15
15
impl < ' a > MarkdownRenderer < ' a > {
16
16
/// Creates a new renderer instance.
17
17
///
18
- /// Per `markdown_to_html `, `base_url` is the base URL prepended to any
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
21
let tags = [
@@ -102,6 +102,7 @@ impl<'a> MarkdownRenderer<'a> {
102
102
103
103
let sanitizer_base_url = base_url. map ( |s| s. to_string ( ) ) ;
104
104
105
+ // Constrain the type of the closures given to the HTML sanitizer.
105
106
fn constrain_closure < F > ( f : F ) -> F
106
107
where
107
108
F : for < ' a > Fn ( & ' a str ) -> Option < Cow < ' a , str > > + Send + Sync ,
@@ -110,6 +111,7 @@ impl<'a> MarkdownRenderer<'a> {
110
111
}
111
112
112
113
let unrelative_url_sanitizer = constrain_closure ( |url| {
114
+ // We have no base URL; allow fragment links only.
113
115
if url. starts_with ( '#' ) {
114
116
return Some ( Cow :: Borrowed ( url) ) ;
115
117
}
@@ -118,6 +120,7 @@ impl<'a> MarkdownRenderer<'a> {
118
120
} ) ;
119
121
120
122
let relative_url_sanitizer = constrain_closure ( move |url| {
123
+ // sanitizer_base_url is Some(String); use it to fix the relative URL.
121
124
if url. starts_with ( '#' ) {
122
125
return Some ( Cow :: Borrowed ( url) ) ;
123
126
}
@@ -179,7 +182,8 @@ impl<'a> MarkdownRenderer<'a> {
179
182
}
180
183
}
181
184
182
- /// Renders Markdown text to sanitized HTML.
185
+ /// Renders Markdown text to sanitized HTML with a given `base_url`.
186
+ /// See `readme_to_html` for the interpretation of `base_url`.
183
187
fn markdown_to_html ( text : & str , base_url : Option < & str > ) -> CargoResult < String > {
184
188
let renderer = MarkdownRenderer :: new ( base_url) ;
185
189
renderer. to_html ( text)
@@ -198,9 +202,9 @@ static MARKDOWN_EXTENSIONS: [&'static str; 7] = [
198
202
] ;
199
203
200
204
/// Renders a readme to sanitized HTML. An appropriate rendering method is chosen depending
201
- /// on the extension of the supplied filename.
205
+ /// on the extension of the supplied ` filename` .
202
206
///
203
- /// The returned text should not contain any harmful HTML tag or attribute (such as iframe,
207
+ /// The returned text will not contain any harmful HTML tag or attribute (such as iframe,
204
208
/// onclick, onmouseover, etc.).
205
209
///
206
210
/// The `base_url` parameter will be used as the base for any relative links found in the
0 commit comments