Skip to content

Commit 1043549

Browse files
authored
Rollup merge of #88632 - camelid:md-opts, r=CraftSpider
Fix issues with Markdown summary options - Use `summary_opts()` for Markdown summaries - Enable all main body Markdown options for summaries
2 parents 257f5ad + 2cc7b7c commit 1043549

File tree

3 files changed

+18
-13
lines changed

3 files changed

+18
-13
lines changed

src/librustdoc/html/markdown.rs

+14-9
Original file line numberDiff line numberDiff line change
@@ -48,17 +48,21 @@ use pulldown_cmark::{
4848
mod tests;
4949

5050
/// Options for rendering Markdown in the main body of documentation.
51-
pub(crate) fn opts() -> Options {
51+
pub(crate) fn main_body_opts() -> Options {
5252
Options::ENABLE_TABLES
5353
| Options::ENABLE_FOOTNOTES
5454
| Options::ENABLE_STRIKETHROUGH
5555
| Options::ENABLE_TASKLISTS
5656
| Options::ENABLE_SMART_PUNCTUATION
5757
}
5858

59-
/// A subset of [`opts()`] used for rendering summaries.
59+
/// Options for rendering Markdown in summaries (e.g., in search results).
6060
pub(crate) fn summary_opts() -> Options {
61-
Options::ENABLE_STRIKETHROUGH | Options::ENABLE_SMART_PUNCTUATION | Options::ENABLE_TABLES
61+
Options::ENABLE_TABLES
62+
| Options::ENABLE_FOOTNOTES
63+
| Options::ENABLE_STRIKETHROUGH
64+
| Options::ENABLE_TASKLISTS
65+
| Options::ENABLE_SMART_PUNCTUATION
6266
}
6367

6468
/// When `to_string` is called, this struct will emit the HTML corresponding to
@@ -981,7 +985,7 @@ impl Markdown<'_> {
981985
}
982986
};
983987

984-
let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut replacer));
988+
let p = Parser::new_with_broken_link_callback(md, main_body_opts(), Some(&mut replacer));
985989
let p = p.into_offset_iter();
986990

987991
let mut s = String::with_capacity(md.len() * 3 / 2);
@@ -1000,7 +1004,7 @@ impl MarkdownWithToc<'_> {
10001004
crate fn into_string(self) -> String {
10011005
let MarkdownWithToc(md, mut ids, codes, edition, playground) = self;
10021006

1003-
let p = Parser::new_ext(md, opts()).into_offset_iter();
1007+
let p = Parser::new_ext(md, main_body_opts()).into_offset_iter();
10041008

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

@@ -1025,7 +1029,7 @@ impl MarkdownHtml<'_> {
10251029
if md.is_empty() {
10261030
return String::new();
10271031
}
1028-
let p = Parser::new_ext(md, opts()).into_offset_iter();
1032+
let p = Parser::new_ext(md, main_body_opts()).into_offset_iter();
10291033

10301034
// Treat inline HTML as plain text.
10311035
let p = p.map(|event| match event.0 {
@@ -1099,7 +1103,7 @@ fn markdown_summary_with_limit(
10991103
}
11001104
};
11011105

1102-
let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut replacer));
1106+
let p = Parser::new_with_broken_link_callback(md, summary_opts(), Some(&mut replacer));
11031107
let mut p = LinkReplacer::new(p, link_names);
11041108

11051109
let mut buf = HtmlWithLimit::new(length_limit);
@@ -1246,7 +1250,8 @@ crate fn markdown_links(md: &str) -> Vec<MarkdownLink> {
12461250
});
12471251
None
12481252
};
1249-
let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut push)).into_offset_iter();
1253+
let p = Parser::new_with_broken_link_callback(md, main_body_opts(), Some(&mut push))
1254+
.into_offset_iter();
12501255

12511256
// There's no need to thread an IdMap through to here because
12521257
// the IDs generated aren't going to be emitted anywhere.
@@ -1285,7 +1290,7 @@ crate fn rust_code_blocks(md: &str, extra_info: &ExtraInfo<'_>) -> Vec<RustCodeB
12851290
return code_blocks;
12861291
}
12871292

1288-
let mut p = Parser::new_ext(md, opts()).into_offset_iter();
1293+
let mut p = Parser::new_ext(md, main_body_opts()).into_offset_iter();
12891294

12901295
while let Some((event, offset)) = p.next() {
12911296
if let Event::Start(Tag::CodeBlock(syntax)) = event {

src/librustdoc/passes/bare_urls.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::Pass;
22
use crate::clean::*;
33
use crate::core::DocContext;
44
use crate::fold::DocFolder;
5-
use crate::html::markdown::opts;
5+
use crate::html::markdown::main_body_opts;
66
use core::ops::Range;
77
use pulldown_cmark::{Event, Parser, Tag};
88
use regex::Regex;
@@ -83,7 +83,7 @@ impl<'a, 'tcx> DocFolder for BareUrlsLinter<'a, 'tcx> {
8383
});
8484
};
8585

86-
let mut p = Parser::new_ext(&dox, opts()).into_offset_iter();
86+
let mut p = Parser::new_ext(&dox, main_body_opts()).into_offset_iter();
8787

8888
while let Some((event, range)) = p.next() {
8989
match event {

src/librustdoc/passes/html_tags.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use super::Pass;
22
use crate::clean::*;
33
use crate::core::DocContext;
44
use crate::fold::DocFolder;
5-
use crate::html::markdown::opts;
5+
use crate::html::markdown::main_body_opts;
66
use core::ops::Range;
77
use pulldown_cmark::{Event, Parser, Tag};
88
use std::iter::Peekable;
@@ -192,7 +192,7 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> {
192192
let mut is_in_comment = None;
193193
let mut in_code_block = false;
194194

195-
let p = Parser::new_ext(&dox, opts()).into_offset_iter();
195+
let p = Parser::new_ext(&dox, main_body_opts()).into_offset_iter();
196196

197197
for (event, range) in p {
198198
match event {

0 commit comments

Comments
 (0)