Don't initialize id-map when rendering md files

Adding these "known" values to the table of used ids is only required
when embedding markdown into a rustdoc  html page and may yield
unexpected results when rendering a standalone `*.md` file.
This commit is contained in:
mitaa 2016-03-26 16:42:38 +01:00
parent 6a76872d71
commit 8779e7baa4
3 changed files with 14 additions and 8 deletions

View File

@ -607,7 +607,7 @@ mod tests {
fn issue_17736() {
let markdown = "# title";
format!("{}", Markdown(markdown));
reset_ids();
reset_ids(true);
}
#[test]
@ -615,7 +615,7 @@ mod tests {
fn t(input: &str, expect: &str) {
let output = format!("{}", Markdown(input));
assert_eq!(output, expect);
reset_ids();
reset_ids(true);
}
t("# Foo bar", "\n<h1 id='foo-bar' class='section-header'>\
@ -654,7 +654,7 @@ mod tests {
<a href='#panics-1'>Panics</a></h1>");
};
test();
reset_ids();
reset_ids(true);
test();
}

View File

@ -378,8 +378,14 @@ fn init_ids() -> HashMap<String, usize> {
/// This method resets the local table of used ID attributes. This is typically
/// used at the beginning of rendering an entire HTML page to reset from the
/// previous state (if any).
pub fn reset_ids() {
USED_ID_MAP.with(|s| *s.borrow_mut() = init_ids());
pub fn reset_ids(embedded: bool) {
USED_ID_MAP.with(|s| {
*s.borrow_mut() = if embedded {
init_ids()
} else {
HashMap::new()
};
});
}
pub fn derive_id(candidate: String) -> String {
@ -1280,7 +1286,7 @@ impl Context {
keywords: &keywords,
};
reset_ids();
reset_ids(true);
// We have a huge number of calls to write, so try to alleviate some
// of the pain by using a buffered writer instead of invoking the
@ -2748,6 +2754,6 @@ fn test_unique_id() {
assert_eq!(&actual[..], expected);
};
test();
reset_ids();
reset_ids(true);
test();
}

View File

@ -83,7 +83,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
}
let title = metadata[0];
reset_ids();
reset_ids(false);
let rendered = if include_toc {
format!("{}", MarkdownWithToc(text))