From ba1a3614acda592c2650e541147c5416fe211c20 Mon Sep 17 00:00:00 2001 From: binarycat Date: Sun, 7 Dec 2025 13:27:01 -0600 Subject: [PATCH] rustdoc: don't strip

from stability notes I believe the reason we were doing this before was that write_html_fmt adds a \n after each

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
events in place of newlines, but that would be a significantly larger change. --- src/librustdoc/html/markdown.rs | 3 --- src/librustdoc/html/markdown/tests.rs | 2 +- src/librustdoc/html/static/css/rustdoc.css | 5 +++-- tests/rustdoc/deprecated.rs | 5 +++++ 4 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index a4d377432c914..e47289e2c667f 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -1479,9 +1479,6 @@ impl MarkdownItemInfo<'_> { let p = HeadingLinks::new(p, None, ids, HeadingOffset::H1); let p = footnotes::Footnotes::new(p, existing_footnotes); let p = TableWrapper::new(p.map(|(ev, _)| ev)); - let p = p.filter(|event| { - !matches!(event, Event::Start(Tag::Paragraph) | Event::End(TagEnd::Paragraph)) - }); html::write_html_fmt(&mut f, p) }) } diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index 61fd428746332..5a470a9f425ad 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -472,7 +472,7 @@ fn test_markdown_html_escape() { let mut idmap = IdMap::new(); let mut output = String::new(); MarkdownItemInfo(input, &mut idmap).write_into(&mut output).unwrap(); - assert_eq!(output, expect, "original: {}", input); + assert_eq!(output, format!("

{}

\n", expect), "original: {}", input); } t("`Struct<'a, T>`", "Struct<'a, T>"); diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index 7f47856948493..069e0d2c06acc 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1577,12 +1577,13 @@ so that we can apply CSS-filters to change the arrow color in themes */ color: var(--main-color); background-color: var(--stab-background-color); width: fit-content; - white-space: pre-wrap; border-radius: 3px; display: inline; vertical-align: baseline; } - +.stab p { + white-space: pre-wrap; +} .stab.portability > code { background: none; color: var(--stab-code-color); diff --git a/tests/rustdoc/deprecated.rs b/tests/rustdoc/deprecated.rs index a84657a3df5aa..c7db816cffcfc 100644 --- a/tests/rustdoc/deprecated.rs +++ b/tests/rustdoc/deprecated.rs @@ -30,3 +30,8 @@ pub struct W; // 'Deprecated: shorthand reason: code$' #[deprecated = "shorthand reason: `code`"] pub struct X; + +//@ matches deprecated/struct.Y.html '//*[@class="stab deprecated"]//p[1]' 'multiple' +//@ matches deprecated/struct.Y.html '//*[@class="stab deprecated"]//p[2]' 'paragraphs' +#[deprecated = "multiple\n\nparagraphs"] +pub struct Y;