Skip to content

Commit ba1a361

Browse files
committed
rustdoc: don't strip <p> from stability notes
I believe the reason we were doing this before was that write_html_fmt adds a \n after each <p> element. I have worked around this by making white-space:pre-wrap apply only to the contents of each paragraph, so the inserted whitespace between paragraphs is not included. Perhaps a better solution would be getting rid of pre-wrap entirely, and instead inserting <br> events in place of newlines, but that would be a significantly larger change.
1 parent 66428d9 commit ba1a361

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

src/librustdoc/html/markdown.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,9 +1479,6 @@ impl MarkdownItemInfo<'_> {
14791479
let p = HeadingLinks::new(p, None, ids, HeadingOffset::H1);
14801480
let p = footnotes::Footnotes::new(p, existing_footnotes);
14811481
let p = TableWrapper::new(p.map(|(ev, _)| ev));
1482-
let p = p.filter(|event| {
1483-
!matches!(event, Event::Start(Tag::Paragraph) | Event::End(TagEnd::Paragraph))
1484-
});
14851482
html::write_html_fmt(&mut f, p)
14861483
})
14871484
}

src/librustdoc/html/markdown/tests.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ fn test_markdown_html_escape() {
472472
let mut idmap = IdMap::new();
473473
let mut output = String::new();
474474
MarkdownItemInfo(input, &mut idmap).write_into(&mut output).unwrap();
475-
assert_eq!(output, expect, "original: {}", input);
475+
assert_eq!(output, format!("<p>{}</p>\n", expect), "original: {}", input);
476476
}
477477

478478
t("`Struct<'a, T>`", "<code>Struct&lt;'a, T&gt;</code>");

src/librustdoc/html/static/css/rustdoc.css

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1577,12 +1577,13 @@ so that we can apply CSS-filters to change the arrow color in themes */
15771577
color: var(--main-color);
15781578
background-color: var(--stab-background-color);
15791579
width: fit-content;
1580-
white-space: pre-wrap;
15811580
border-radius: 3px;
15821581
display: inline;
15831582
vertical-align: baseline;
15841583
}
1585-
1584+
.stab p {
1585+
white-space: pre-wrap;
1586+
}
15861587
.stab.portability > code {
15871588
background: none;
15881589
color: var(--stab-code-color);

tests/rustdoc/deprecated.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,3 +30,8 @@ pub struct W;
3030
// 'Deprecated: shorthand reason: code$'
3131
#[deprecated = "shorthand reason: `code`"]
3232
pub struct X;
33+
34+
//@ matches deprecated/struct.Y.html '//*[@class="stab deprecated"]//p[1]' 'multiple'
35+
//@ matches deprecated/struct.Y.html '//*[@class="stab deprecated"]//p[2]' 'paragraphs'
36+
#[deprecated = "multiple\n\nparagraphs"]
37+
pub struct Y;

0 commit comments

Comments
 (0)