Auto merge of #79400 - camelid:rustdoc-summary_opts, r=GuillaumeGomez

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.
This commit is contained in:
bors 2020-11-25 14:08:47 +00:00
commit 36018a4d06

View File

@ -43,10 +43,16 @@ use pulldown_cmark::{html, BrokenLink, CodeBlockKind, CowStr, Event, Options, Pa
#[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 @@ crate fn plain_text_summary(md: &str) -> String {
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) => {