From dedf6fcde48ccebe8b81654aa0e3ac1c78347a9b Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 22 Sep 2022 14:54:38 -0700 Subject: [PATCH 1/2] rustdoc: clean up CSS/DOM for deprecation warnings --- src/librustdoc/html/markdown.rs | 19 ++++++++----------- src/librustdoc/html/render/mod.rs | 13 ++++--------- src/librustdoc/html/static/css/rustdoc.css | 4 ---- 3 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 43d07d4a533..8e53fbbcd19 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -111,14 +111,9 @@ pub(crate) struct MarkdownWithToc<'a>( pub(crate) Edition, pub(crate) &'a Option, ); -/// A tuple struct like `Markdown` that renders the markdown escaping HTML tags. -pub(crate) struct MarkdownHtml<'a>( - pub(crate) &'a str, - pub(crate) &'a mut IdMap, - pub(crate) ErrorCodes, - pub(crate) Edition, - pub(crate) &'a Option, -); +/// A tuple struct like `Markdown` that renders the markdown escaping HTML tags +/// and includes no paragraph tags. +pub(crate) struct MarkdownItemInfo<'a>(pub(crate) &'a str, pub(crate) &'a mut IdMap); /// A tuple struct like `Markdown` that renders only the first paragraph. pub(crate) struct MarkdownSummaryLine<'a>(pub &'a str, pub &'a [RenderedLink]); @@ -1072,9 +1067,9 @@ pub(crate) fn into_string(self) -> String { } } -impl MarkdownHtml<'_> { +impl MarkdownItemInfo<'_> { pub(crate) fn into_string(self) -> String { - let MarkdownHtml(md, ids, codes, edition, playground) = self; + let MarkdownItemInfo(md, ids) = self; // This is actually common enough to special-case if md.is_empty() { @@ -1093,7 +1088,9 @@ pub(crate) fn into_string(self) -> String { let p = HeadingLinks::new(p, None, ids, HeadingOffset::H1); let p = Footnotes::new(p); let p = TableWrapper::new(p.map(|(ev, _)| ev)); - let p = CodeBlocks::new(p, codes, edition, playground); + let p = p.filter(|event| { + !matches!(event, Event::Start(Tag::Paragraph) | Event::End(Tag::Paragraph)) + }); html::push_html(&mut s, p); s diff --git a/src/librustdoc/html/render/mod.rs b/src/librustdoc/html/render/mod.rs index 7e5e4df43d2..ca4e65d7028 100644 --- a/src/librustdoc/html/render/mod.rs +++ b/src/librustdoc/html/render/mod.rs @@ -74,7 +74,9 @@ PrintWithSpace, }; use crate::html::highlight; -use crate::html::markdown::{HeadingOffset, IdMap, Markdown, MarkdownHtml, MarkdownSummaryLine}; +use crate::html::markdown::{ + HeadingOffset, IdMap, Markdown, MarkdownItemInfo, MarkdownSummaryLine, +}; use crate::html::sources; use crate::html::static_files::SCRAPE_EXAMPLES_HELP_MD; use crate::scrape_examples::{CallData, CallLocation}; @@ -582,7 +584,6 @@ fn short_item_info( parent: Option<&clean::Item>, ) -> Vec { let mut extra_info = vec![]; - let error_codes = cx.shared.codes; if let Some(depr @ Deprecation { note, since, is_since_rustc_version: _, suggestion: _ }) = item.deprecation(cx.tcx()) @@ -606,13 +607,7 @@ fn short_item_info( if let Some(note) = note { let note = note.as_str(); - let html = MarkdownHtml( - note, - &mut cx.id_map, - error_codes, - cx.shared.edition(), - &cx.shared.playground, - ); + let html = MarkdownItemInfo(note, &mut cx.id_map); message.push_str(&format!(": {}", html.into_string())); } extra_info.push(format!( diff --git a/src/librustdoc/html/static/css/rustdoc.css b/src/librustdoc/html/static/css/rustdoc.css index f21179ec558..3ce9407cb2d 100644 --- a/src/librustdoc/html/static/css/rustdoc.css +++ b/src/librustdoc/html/static/css/rustdoc.css @@ -1078,10 +1078,6 @@ so that we can apply CSS-filters to change the arrow color in themes */ font-size: 0.875rem; font-weight: normal; } -.stab p { - display: inline; - margin: 0; -} .stab .emoji { font-size: 1.25rem; From 51f335deca435bd4899b3cde0555bbaaa6afdbef Mon Sep 17 00:00:00 2001 From: Michael Howell Date: Thu, 22 Sep 2022 15:41:32 -0700 Subject: [PATCH 2/2] rustdoc: fix unit tests --- src/librustdoc/html/markdown/tests.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/markdown/tests.rs b/src/librustdoc/html/markdown/tests.rs index 5c0bf0ed942..e4f72a05789 100644 --- a/src/librustdoc/html/markdown/tests.rs +++ b/src/librustdoc/html/markdown/tests.rs @@ -1,5 +1,5 @@ use super::{find_testable_code, plain_text_summary, short_markdown_summary}; -use super::{ErrorCodes, HeadingOffset, IdMap, Ignore, LangString, Markdown, MarkdownHtml}; +use super::{ErrorCodes, HeadingOffset, IdMap, Ignore, LangString, Markdown, MarkdownItemInfo}; use rustc_span::edition::{Edition, DEFAULT_EDITION}; #[test] @@ -279,14 +279,13 @@ fn t(input: &str, expect: &str) { fn test_markdown_html_escape() { fn t(input: &str, expect: &str) { let mut idmap = IdMap::new(); - let output = - MarkdownHtml(input, &mut idmap, ErrorCodes::Yes, DEFAULT_EDITION, &None).into_string(); + let output = MarkdownItemInfo(input, &mut idmap).into_string(); assert_eq!(output, expect, "original: {}", input); } - t("`Struct<'a, T>`", "

Struct<'a, T>

\n"); - t("Struct<'a, T>", "

Struct<’a, T>

\n"); - t("Struct
", "

Struct<br>

\n"); + t("`Struct<'a, T>`", "Struct<'a, T>"); + t("Struct<'a, T>", "Struct<’a, T>"); + t("Struct
", "Struct<br>"); } #[test]