]> git.lizzy.rs Git - rust.git/blobdiff - crates/rust-analyzer/src/markdown.rs
Replaced fold with for loop
[rust.git] / crates / rust-analyzer / src / markdown.rs
index 35eaffba8ca99a4e88ca5f0d20f13c946820a7b1..59c904f86e7ed0acc3827b0b7a768d004cf448a7 100644 (file)
@@ -25,6 +25,13 @@ pub(crate) fn format_docs(src: &str) -> String {
             }
         }
 
+        if in_code_block {
+            let trimmed = line.trim_start();
+            if trimmed.starts_with("##") {
+                line = &trimmed[1..];
+            }
+        }
+
         processed_lines.push(line);
     }
     processed_lines.join("\n")
@@ -136,4 +143,14 @@ fn test_code_blocks_in_comments_marked_as_text() {
             "```text\nfiller\ntext\n```\nSome comment.\n```rust\nlet a = 1;\n```"
         );
     }
+
+    #[test]
+    fn test_format_docs_handles_escape_double_hashes() {
+        let comment = r#"```rust
+let s = "foo
+## bar # baz";
+```"#;
+
+        assert_eq!(format_docs(comment), "```rust\nlet s = \"foo\n# bar # baz\";\n```");
+    }
 }