Skip to content

Commit be17eab

Browse files
author
Daniil Kolesnichenko
committed
fix(rustdoc): don't escape double hashes outside of Rust code blocks
Fixes rust-lang#14376
1 parent 284c174 commit be17eab

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

crates/rust-analyzer/src/markdown.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub(crate) fn format_docs(src: &str) -> String {
2828

2929
if in_code_block {
3030
let trimmed = line.trim_start();
31-
if trimmed.starts_with("##") {
31+
if is_rust && trimmed.starts_with("##") {
3232
line = &trimmed[1..];
3333
}
3434
}
@@ -154,4 +154,12 @@ let s = "foo
154154

155155
assert_eq!(format_docs(comment), "```rust\nlet s = \"foo\n# bar # baz\";\n```");
156156
}
157+
158+
#[test]
159+
fn test_format_docs_handles_double_hashes_non_rust() {
160+
let comment = r#"```markdown
161+
## A second-level heading
162+
```"#;
163+
assert_eq!(format_docs(comment), "```markdown\n## A second-level heading\n```");
164+
}
157165
}

0 commit comments

Comments
 (0)