Skip to content

Commit

Permalink
Add summary_opts() for Markdown summary rendering options
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
camelid committed Nov 25, 2020
1 parent 1c389ff commit 50c2739
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions src/librustdoc/html/markdown.rs
Expand Up @@ -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>(
Expand Down Expand Up @@ -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();

Expand All @@ -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) => {
Expand Down

0 comments on commit 50c2739

Please sign in to comment.