Skip to content

Commit 36018a4

Browse files
committed
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.
2 parents 20dcbf0 + 50c2739 commit 36018a4

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

Diff for: src/librustdoc/html/markdown.rs

+8-6
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,16 @@ use pulldown_cmark::{html, BrokenLink, CodeBlockKind, CowStr, Event, Options, Pa
4343
#[cfg(test)]
4444
mod tests;
4545

46+
/// Options for rendering Markdown in the main body of documentation.
4647
pub(crate) fn opts() -> Options {
4748
Options::ENABLE_TABLES | Options::ENABLE_FOOTNOTES | Options::ENABLE_STRIKETHROUGH
4849
}
4950

51+
/// A subset of [`opts()`] used for rendering summaries.
52+
pub(crate) fn summary_opts() -> Options {
53+
Options::ENABLE_STRIKETHROUGH
54+
}
55+
5056
/// When `to_string` is called, this struct will emit the HTML corresponding to
5157
/// the rendered version of the contained markdown string.
5258
pub struct Markdown<'a>(
@@ -1021,11 +1027,7 @@ impl MarkdownSummaryLine<'_> {
10211027
}
10221028
};
10231029

1024-
let p = Parser::new_with_broken_link_callback(
1025-
md,
1026-
Options::ENABLE_STRIKETHROUGH,
1027-
Some(&mut replacer),
1028-
);
1030+
let p = Parser::new_with_broken_link_callback(md, summary_opts(), Some(&mut replacer));
10291031

10301032
let mut s = String::new();
10311033

@@ -1047,7 +1049,7 @@ crate fn plain_text_summary(md: &str) -> String {
10471049

10481050
let mut s = String::with_capacity(md.len() * 3 / 2);
10491051

1050-
for event in Parser::new_ext(md, Options::ENABLE_STRIKETHROUGH) {
1052+
for event in Parser::new_ext(md, summary_opts()) {
10511053
match &event {
10521054
Event::Text(text) => s.push_str(text),
10531055
Event::Code(code) => {

0 commit comments

Comments
 (0)