diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 86f56660d3a64..faf361f029059 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -268,6 +268,10 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { text.with_c_str(|p| unsafe { hoedown_buffer_puts(ob, p) }); } + if used_header_map.get().is_none() { + reset_headers(); + } + unsafe { let ob = hoedown_buffer_new(DEF_OUNIT); let renderer = hoedown_html_renderer_new(0, 0); @@ -446,7 +450,7 @@ impl<'a> fmt::Show for MarkdownWithToc<'a> { #[cfg(test)] mod tests { - use super::LangString; + use super::{LangString, Markdown}; #[test] fn test_lang_string_parse() { @@ -474,4 +478,10 @@ mod tests { t("{.example .rust}", false,false,false,false,false); t("{.test_harness .rust}", false,false,false,false,true); } + + #[test] + fn issue_17736() { + let markdown = "# title"; + format!("{}", Markdown(markdown.as_slice())); + } }