diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 150ad51c7bb..f68e82501e9 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -289,6 +289,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { // html for text rather than the raw text. let mut id = s.clone(); let repl_sub = vec!["", "", "", "", + "", "", "<", ">", "&", "'", """]; for sub in repl_sub { id = id.replace(sub, ""); @@ -326,8 +327,8 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result { }); // Render the HTML - let text = format!(r##"{sec}{}"##, + let text = format!("\ + {sec}{}", s, lvl = level, id = id, sec = sec); let text = CString::new(text).unwrap(); @@ -612,6 +613,27 @@ mod tests { format!("{}", Markdown(markdown)); } + #[test] + fn test_header() { + fn t(input: &str, expect: &str) { + let output = format!("{}", Markdown(input)); + assert_eq!(output, expect); + } + + t("# Foo bar", "\n

\ + Foo bar

"); + t("## Foo-bar_baz qux", "\n

Foo-bar_baz qux

"); + t("### **Foo** *bar* baz!?!& -_qux_-%", + "\n

\ + Foo \ + bar baz!?!& -_qux_-%

"); + t("####**Foo?** & \\*bar?!* _`baz`_ ❤ #qux", + "\n

\ + Foo? & *bar?!* \ + baz ❤ #qux

"); + } + #[test] fn test_plain_summary_line() { fn t(input: &str, expect: &str) {