From 50c2739bb4f5692134a152990d9ea96127c47e90 Mon Sep 17 00:00:00 2001 From: Camelid Date: Tue, 24 Nov 2020 19:54:41 -0800 Subject: [PATCH] Add `summary_opts()` for Markdown summary rendering options We have a similar function `opts()` that is for rendering the main body of the documentation, but until now we just constructed the options for rendering summaries on the fly. This is a problem if/when we change the enabled options since the different places can get out-of-sync. --- src/librustdoc/html/markdown.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 880c859dd1b..8ce686c6550 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -43,10 +43,16 @@ #[cfg(test)] mod tests; +/// Options for rendering Markdown in the main body of documentation. pub(crate) fn opts() -> Options { Options::ENABLE_TABLES | Options::ENABLE_FOOTNOTES | Options::ENABLE_STRIKETHROUGH } +/// A subset of [`opts()`] used for rendering summaries. +pub(crate) fn summary_opts() -> Options { + Options::ENABLE_STRIKETHROUGH +} + /// When `to_string` is called, this struct will emit the HTML corresponding to /// the rendered version of the contained markdown string. pub struct Markdown<'a>( @@ -1021,11 +1027,7 @@ impl MarkdownSummaryLine<'_> { } }; - let p = Parser::new_with_broken_link_callback( - md, - Options::ENABLE_STRIKETHROUGH, - Some(&mut replacer), - ); + let p = Parser::new_with_broken_link_callback(md, summary_opts(), Some(&mut replacer)); let mut s = String::new(); @@ -1047,7 +1049,7 @@ impl MarkdownSummaryLine<'_> { let mut s = String::with_capacity(md.len() * 3 / 2); - for event in Parser::new_ext(md, Options::ENABLE_STRIKETHROUGH) { + for event in Parser::new_ext(md, summary_opts()) { match &event { Event::Text(text) => s.push_str(text), Event::Code(code) => {