diff options
| author | Joshua Nelson <jyn514@gmail.com> | 2021-04-22 14:50:56 -0400 |
|---|---|---|
| committer | Joshua Nelson <jyn514@gmail.com> | 2021-04-22 18:43:16 -0400 |
| commit | af6c3201fc3d5ec2559836454ea4f43eec583fa2 (patch) | |
| tree | 0efcf9486d76055591f41f53083487b2d887f268 /src/librustdoc/html | |
| parent | 25c15cdbe070f49d708f34750df2632e38bd4846 (diff) | |
| download | rust-af6c3201fc3d5ec2559836454ea4f43eec583fa2.tar.gz rust-af6c3201fc3d5ec2559836454ea4f43eec583fa2.zip | |
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.
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)) } |
