mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-26 08:44:35 +00:00
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:
parent
6a76872d71
commit
8779e7baa4
@ -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();
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -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))
|
||||
|
Loading…
Reference in New Issue
Block a user