diff options
| author | bors <bors@rust-lang.org> | 2021-04-23 13:28:04 +0000 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2021-04-23 13:28:04 +0000 |
| commit | 9a352326112e4fd993e339cbd4eabae06d4979b9 (patch) | |
| tree | 3c8fbbcf924b3fabc760ba890470a3b7566403fe /src/librustdoc/html | |
| parent | 236580bc5bed062ad3fc34f445af8e8a54713258 (diff) | |
| parent | af6c3201fc3d5ec2559836454ea4f43eec583fa2 (diff) | |
| download | rust-9a352326112e4fd993e339cbd4eabae06d4979b9.tar.gz rust-9a352326112e4fd993e339cbd4eabae06d4979b9.zip | |
Auto merge of #84445 - jyn514:hidden, r=<try>
rustdoc: Hide `#text` in doc-tests Since `#![attr]` and `#[attr]` are the only valid syntax that start with `#`, we can just special case those two tokens. Fixes https://github.com/rust-lang/rust/issues/83284.
Diffstat (limited to 'src/librustdoc/html')
| -rw-r--r-- | src/librustdoc/html/markdown.rs | 19 |
1 files changed, 13 insertions, 6 deletions
diff --git a/src/librustdoc/html/markdown.rs b/src/librustdoc/html/markdown.rs index 509f1730557..f1c9550b5ac 100644 --- a/src/librustdoc/html/markdown.rs +++ b/src/librustdoc/html/markdown.rs @@ -147,12 +147,19 @@ fn map_line(s: &str) -> Line<'_> { let trimmed = s.trim(); if trimmed.starts_with("##") { Line::Shown(Cow::Owned(s.replacen("##", "#", 1))) - } else if let Some(stripped) = trimmed.strip_prefix("# ") { - // # text - Line::Hidden(&stripped) - } else if trimmed == "#" { - // We cannot handle '#text' because it could be #[attr]. - Line::Hidden("") + } else if trimmed.starts_with('#') { + let mut without_hash = trimmed[1..].trim_start(); + if without_hash.starts_with('!') { + // #! text + without_hash = without_hash[1..].trim_start_matches(' '); + } + if without_hash.starts_with('[') { + // #[attr] or #![attr] + Line::Shown(Cow::Borrowed(s)) + } else { + // #text + Line::Hidden(without_hash) + } } else { Line::Shown(Cow::Borrowed(s)) } |
