Skip to content

Commit 8779e7b

Browse files
committed
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.
1 parent 6a76872 commit 8779e7b

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -607,15 +607,15 @@ mod tests {
607607
fn issue_17736() {
608608
let markdown = "# title";
609609
format!("{}", Markdown(markdown));
610-
reset_ids();
610+
reset_ids(true);
611611
}
612612

613613
#[test]
614614
fn test_header() {
615615
fn t(input: &str, expect: &str) {
616616
let output = format!("{}", Markdown(input));
617617
assert_eq!(output, expect);
618-
reset_ids();
618+
reset_ids(true);
619619
}
620620

621621
t("# Foo bar", "\n<h1 id='foo-bar' class='section-header'>\
@@ -654,7 +654,7 @@ mod tests {
654654
<a href='#panics-1'>Panics</a></h1>");
655655
};
656656
test();
657-
reset_ids();
657+
reset_ids(true);
658658
test();
659659
}
660660

src/librustdoc/html/render.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -378,8 +378,14 @@ fn init_ids() -> HashMap<String, usize> {
378378
/// This method resets the local table of used ID attributes. This is typically
379379
/// used at the beginning of rendering an entire HTML page to reset from the
380380
/// previous state (if any).
381-
pub fn reset_ids() {
382-
USED_ID_MAP.with(|s| *s.borrow_mut() = init_ids());
381+
pub fn reset_ids(embedded: bool) {
382+
USED_ID_MAP.with(|s| {
383+
*s.borrow_mut() = if embedded {
384+
init_ids()
385+
} else {
386+
HashMap::new()
387+
};
388+
});
383389
}
384390

385391
pub fn derive_id(candidate: String) -> String {
@@ -1280,7 +1286,7 @@ impl Context {
12801286
keywords: &keywords,
12811287
};
12821288

1283-
reset_ids();
1289+
reset_ids(true);
12841290

12851291
// We have a huge number of calls to write, so try to alleviate some
12861292
// of the pain by using a buffered writer instead of invoking the
@@ -2748,6 +2754,6 @@ fn test_unique_id() {
27482754
assert_eq!(&actual[..], expected);
27492755
};
27502756
test();
2751-
reset_ids();
2757+
reset_ids(true);
27522758
test();
27532759
}

src/librustdoc/markdown.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ pub fn render(input: &str, mut output: PathBuf, matches: &getopts::Matches,
8383
}
8484
let title = metadata[0];
8585

86-
reset_ids();
86+
reset_ids(false);
8787

8888
let rendered = if include_toc {
8989
format!("{}", MarkdownWithToc(text))

0 commit comments

Comments
 (0)