diff options
Diffstat (limited to '')
-rw-r--r-- | src/librustdoc/html/markdown.rs | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 52a2effca..1e1c657b0 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<Playground>, ); -/// 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<Playground>, -); +/// 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]); @@ -251,8 +246,6 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> { _ => {} } } - let lines = origtext.lines().filter_map(|l| map_line(l).for_html()); - let text = lines.intersperse("\n".into()).collect::<String>(); let parse_result = match kind { CodeBlockKind::Fenced(ref lang) => { @@ -265,7 +258,7 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> { <pre class=\"language-{}\"><code>{}</code></pre>\ </div>", lang, - Escape(&text), + Escape(&origtext), ) .into(), )); @@ -275,6 +268,9 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> { CodeBlockKind::Indented => Default::default(), }; + let lines = origtext.lines().filter_map(|l| map_line(l).for_html()); + let text = lines.intersperse("\n".into()).collect::<String>(); + compile_fail = parse_result.compile_fail; should_panic = parse_result.should_panic; ignore = parse_result.ignore; @@ -330,34 +326,27 @@ impl<'a, I: Iterator<Item = Event<'a>>> Iterator for CodeBlocks<'_, 'a, I> { }); let tooltip = if ignore != Ignore::None { - Some((None, "ignore")) + highlight::Tooltip::Ignore } else if compile_fail { - Some((None, "compile_fail")) + highlight::Tooltip::CompileFail } else if should_panic { - Some((None, "should_panic")) + highlight::Tooltip::ShouldPanic } else if explicit_edition { - Some((Some(edition), "edition")) + highlight::Tooltip::Edition(edition) } else { - None + highlight::Tooltip::None }; // insert newline to clearly separate it from the // previous block so we can shorten the html output let mut s = Buffer::new(); s.push_str("\n"); - highlight::render_with_highlighting( + + highlight::render_example_with_highlighting( &text, &mut s, - Some(&format!( - "rust-example-rendered{}", - if let Some((_, class)) = tooltip { format!(" {}", class) } else { String::new() } - )), - playground_button.as_deref(), tooltip, - edition, - None, - None, - None, + playground_button.as_deref(), ); Some(Event::Html(s.into_inner().into())) } @@ -825,11 +814,8 @@ impl<'tcx> ExtraInfo<'tcx> { crate::lint::INVALID_CODEBLOCK_ATTRIBUTES, hir_id, self.sp, - |lint| { - let mut diag = lint.build(msg); - diag.help(help); - diag.emit(); - }, + msg, + |lint| lint.help(help), ); } } @@ -1079,9 +1065,9 @@ impl MarkdownWithToc<'_> { } } -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() { @@ -1100,7 +1086,9 @@ impl MarkdownHtml<'_> { 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 @@ -1126,7 +1114,11 @@ impl MarkdownSummaryLine<'_> { let mut s = String::new(); - html::push_html(&mut s, LinkReplacer::new(SummaryLine::new(p), links)); + let without_paragraphs = LinkReplacer::new(SummaryLine::new(p), links).filter(|event| { + !matches!(event, Event::Start(Tag::Paragraph) | Event::End(Tag::Paragraph)) + }); + + html::push_html(&mut s, without_paragraphs); s } @@ -1442,10 +1434,13 @@ static DEFAULT_ID_MAP: Lazy<FxHashMap<Cow<'static, str>, usize>> = Lazy::new(|| fn init_id_map() -> FxHashMap<Cow<'static, str>, usize> { let mut map = FxHashMap::default(); // This is the list of IDs used in Javascript. + map.insert("help".into(), 1); map.insert("settings".into(), 1); map.insert("not-displayed".into(), 1); map.insert("alternative-display".into(), 1); map.insert("search".into(), 1); + map.insert("crate-search".into(), 1); + map.insert("crate-search-div".into(), 1); // This is the list of IDs used in HTML generated in Rust (including the ones // used in tera template files). map.insert("mainThemeStyle".into(), 1); @@ -1453,7 +1448,6 @@ fn init_id_map() -> FxHashMap<Cow<'static, str>, usize> { map.insert("settings-menu".into(), 1); map.insert("help-button".into(), 1); map.insert("main-content".into(), 1); - map.insert("crate-search".into(), 1); map.insert("toggle-all-docs".into(), 1); map.insert("all-types".into(), 1); map.insert("default-settings".into(), 1); |