Skip to content

Commit 3f64fd3

Browse files
committed
some more docs
1 parent 59d144a commit 3f64fd3

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/render.rs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ struct MarkdownRenderer<'a> {
1515
impl<'a> MarkdownRenderer<'a> {
1616
/// Creates a new renderer instance.
1717
///
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
1919
/// relative links in the input document. See that function for more detail.
2020
fn new(base_url: Option<&'a str>) -> MarkdownRenderer<'a> {
2121
let tags = [
@@ -102,6 +102,7 @@ impl<'a> MarkdownRenderer<'a> {
102102

103103
let sanitizer_base_url = base_url.map(|s| s.to_string());
104104

105+
// Constrain the type of the closures given to the HTML sanitizer.
105106
fn constrain_closure<F>(f: F) -> F
106107
where
107108
F: for<'a> Fn(&'a str) -> Option<Cow<'a, str>> + Send + Sync,
@@ -110,6 +111,7 @@ impl<'a> MarkdownRenderer<'a> {
110111
}
111112

112113
let unrelative_url_sanitizer = constrain_closure(|url| {
114+
// We have no base URL; allow fragment links only.
113115
if url.starts_with('#') {
114116
return Some(Cow::Borrowed(url));
115117
}
@@ -118,6 +120,7 @@ impl<'a> MarkdownRenderer<'a> {
118120
});
119121

120122
let relative_url_sanitizer = constrain_closure(move |url| {
123+
// sanitizer_base_url is Some(String); use it to fix the relative URL.
121124
if url.starts_with('#') {
122125
return Some(Cow::Borrowed(url));
123126
}
@@ -179,7 +182,8 @@ impl<'a> MarkdownRenderer<'a> {
179182
}
180183
}
181184

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`.
183187
fn markdown_to_html(text: &str, base_url: Option<&str>) -> CargoResult<String> {
184188
let renderer = MarkdownRenderer::new(base_url);
185189
renderer.to_html(text)
@@ -198,9 +202,9 @@ static MARKDOWN_EXTENSIONS: [&'static str; 7] = [
198202
];
199203

200204
/// 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`.
202206
///
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,
204208
/// onclick, onmouseover, etc.).
205209
///
206210
/// The `base_url` parameter will be used as the base for any relative links found in the

0 commit comments

Comments
 (0)