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.
This commit is contained in:
commit
9a35232611
3 changed files with 44 additions and 6 deletions
|
|
@ -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))
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue