Skip to content

Commit

Permalink
Rollup merge of #88632 - camelid:md-opts, r=CraftSpider
Browse files Browse the repository at this point in the history
Fix issues with Markdown summary options

- Use `summary_opts()` for Markdown summaries
- Enable all main body Markdown options for summaries
  • Loading branch information
Manishearth authored Sep 10, 2021
2 parents 257f5ad + 2cc7b7c commit 1043549
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 13 deletions.
23 changes: 14 additions & 9 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,17 +48,21 @@ use pulldown_cmark::{
mod tests;

/// Options for rendering Markdown in the main body of documentation.
pub(crate) fn opts() -> Options {
pub(crate) fn main_body_opts() -> Options {
Options::ENABLE_TABLES
| Options::ENABLE_FOOTNOTES
| Options::ENABLE_STRIKETHROUGH
| Options::ENABLE_TASKLISTS
| Options::ENABLE_SMART_PUNCTUATION
}

/// A subset of [`opts()`] used for rendering summaries.
/// Options for rendering Markdown in summaries (e.g., in search results).
pub(crate) fn summary_opts() -> Options {
Options::ENABLE_STRIKETHROUGH | Options::ENABLE_SMART_PUNCTUATION | Options::ENABLE_TABLES
Options::ENABLE_TABLES
| Options::ENABLE_FOOTNOTES
| Options::ENABLE_STRIKETHROUGH
| Options::ENABLE_TASKLISTS
| Options::ENABLE_SMART_PUNCTUATION
}

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

let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut replacer));
let p = Parser::new_with_broken_link_callback(md, main_body_opts(), Some(&mut replacer));
let p = p.into_offset_iter();

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

let p = Parser::new_ext(md, opts()).into_offset_iter();
let p = Parser::new_ext(md, main_body_opts()).into_offset_iter();

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

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

// Treat inline HTML as plain text.
let p = p.map(|event| match event.0 {
Expand Down Expand Up @@ -1099,7 +1103,7 @@ fn markdown_summary_with_limit(
}
};

let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut replacer));
let p = Parser::new_with_broken_link_callback(md, summary_opts(), Some(&mut replacer));
let mut p = LinkReplacer::new(p, link_names);

let mut buf = HtmlWithLimit::new(length_limit);
Expand Down Expand Up @@ -1246,7 +1250,8 @@ crate fn markdown_links(md: &str) -> Vec<MarkdownLink> {
});
None
};
let p = Parser::new_with_broken_link_callback(md, opts(), Some(&mut push)).into_offset_iter();
let p = Parser::new_with_broken_link_callback(md, main_body_opts(), Some(&mut push))
.into_offset_iter();

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

let mut p = Parser::new_ext(md, opts()).into_offset_iter();
let mut p = Parser::new_ext(md, main_body_opts()).into_offset_iter();

while let Some((event, offset)) = p.next() {
if let Event::Start(Tag::CodeBlock(syntax)) = event {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/passes/bare_urls.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::Pass;
use crate::clean::*;
use crate::core::DocContext;
use crate::fold::DocFolder;
use crate::html::markdown::opts;
use crate::html::markdown::main_body_opts;
use core::ops::Range;
use pulldown_cmark::{Event, Parser, Tag};
use regex::Regex;
Expand Down Expand Up @@ -83,7 +83,7 @@ impl<'a, 'tcx> DocFolder for BareUrlsLinter<'a, 'tcx> {
});
};

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

while let Some((event, range)) = p.next() {
match event {
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/passes/html_tags.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use super::Pass;
use crate::clean::*;
use crate::core::DocContext;
use crate::fold::DocFolder;
use crate::html::markdown::opts;
use crate::html::markdown::main_body_opts;
use core::ops::Range;
use pulldown_cmark::{Event, Parser, Tag};
use std::iter::Peekable;
Expand Down Expand Up @@ -192,7 +192,7 @@ impl<'a, 'tcx> DocFolder for InvalidHtmlTagsLinter<'a, 'tcx> {
let mut is_in_comment = None;
let mut in_code_block = false;

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

for (event, range) in p {
match event {
Expand Down

0 comments on commit 1043549

Please sign in to comment.