Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add summary_opts() for Markdown summary rendering options #79400

Merged
merged 1 commit into from
Nov 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 8 additions & 6 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
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