Skip to content

Commit

Permalink
Auto merge of rust-lang#118825 - GuillaumeGomez:double-hash-handling,…
Browse files Browse the repository at this point in the history
… r=<try>

Remove weird handling of ## in code examples

As mentioned in rust-lang#118711, the handling of `##` in code blocks in code examples is very surprising. Let's see if crates are using it with a crater run.

r? `@notriddle`
  • Loading branch information
bors committed Dec 11, 2023
2 parents 6f40082 + 289eeac commit 26fc5aa
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
4 changes: 1 addition & 3 deletions src/librustdoc/html/markdown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,7 @@ impl<'a> Line<'a> {
// then reallocate to remove it; which would make us return a String.
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("# ") {
if let Some(stripped) = trimmed.strip_prefix("# ") {
// # text
Line::Hidden(stripped)
} else if trimmed == "#" {
Expand Down
10 changes: 5 additions & 5 deletions tests/rustdoc/issue-41783.codeblock.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<code># single
## double
### triple
<span class="attr">#[outer]
#![inner]</span></code>
<code>## single
### double
#### triple
#<span class="attr">#[outer]
</span>#<span class="attr">#![inner]</span></code>
2 changes: 1 addition & 1 deletion tests/rustdoc/issue-41783.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// @hasraw - '<span class="attr">#[outer]'
// @!hasraw - '<span class="attr">#[outer]</span>'
// @hasraw - '#![inner]</span>'
// @!hasraw - '<span class="attr">#![inner]</span>'
// @hasraw - '#<span class="attr">#![inner]</span>'
// @snapshot 'codeblock' - '//*[@class="toggle top-doc"]/*[@class="docblock"]//pre/code'

/// ```no_run
Expand Down

0 comments on commit 26fc5aa

Please sign in to comment.