Skip to content

Commit 09c1ce1

Browse files
committed
rustdoc: added tests for header rendering & minor fixes
1 parent d6f0a21 commit 09c1ce1

File tree

1 file changed

+24
-2
lines changed

1 file changed

+24
-2
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
289289
// html for text rather than the raw text.
290290
let mut id = s.clone();
291291
let repl_sub = vec!["<em>", "</em>", "<code>", "</code>",
292+
"<strong>", "</strong>",
292293
"&lt;", "&gt;", "&amp;", "&#39;", "&quot;"];
293294
for sub in repl_sub {
294295
id = id.replace(sub, "");
@@ -326,8 +327,8 @@ pub fn render(w: &mut fmt::Formatter, s: &str, print_toc: bool) -> fmt::Result {
326327
});
327328

328329
// Render the HTML
329-
let text = format!(r##"<h{lvl} id="{id}" class='section-header'><a
330-
href="#{id}">{sec}{}</a></h{lvl}>"##,
330+
let text = format!("<h{lvl} id='{id}' class='section-header'>\
331+
<a href='#{id}'>{sec}{}</a></h{lvl}>",
331332
s, lvl = level, id = id, sec = sec);
332333

333334
let text = CString::new(text).unwrap();
@@ -612,6 +613,27 @@ mod tests {
612613
format!("{}", Markdown(markdown));
613614
}
614615

616+
#[test]
617+
fn test_header() {
618+
fn t(input: &str, expect: &str) {
619+
let output = format!("{}", Markdown(input));
620+
assert_eq!(output, expect);
621+
}
622+
623+
t("# Foo bar", "\n<h1 id='foo-bar' class='section-header'>\
624+
<a href='#foo-bar'>Foo bar</a></h1>");
625+
t("## Foo-bar_baz qux", "\n<h2 id='foo-bar_baz-qux' class=\'section-\
626+
header'><a href='#foo-bar_baz-qux'>Foo-bar_baz qux</a></h2>");
627+
t("### **Foo** *bar* baz!?!& -_qux_-%",
628+
"\n<h3 id='foo-bar-baz--_qux_-' class='section-header'>\
629+
<a href='#foo-bar-baz--_qux_-'><strong>Foo</strong> \
630+
<em>bar</em> baz!?!&amp; -_qux_-%</a></h3>");
631+
t("####**Foo?** & \\*bar?!* _`baz`_ ❤ #qux",
632+
"\n<h4 id='foo--bar--baz--qux' class='section-header'>\
633+
<a href='#foo--bar--baz--qux'><strong>Foo?</strong> &amp; *bar?!* \
634+
<em><code>baz</code></em> ❤ #qux</a></h4>");
635+
}
636+
615637
#[test]
616638
fn test_plain_summary_line() {
617639
fn t(input: &str, expect: &str) {

0 commit comments

Comments
 (0)