mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-10-02 22:54:58 +00:00
Merge #11869
11869: fix: code blocks with tilde also works like code block r=Veykril a=moreal The `rustdoc` uses the `pulldown_cmark` package to parse *doc_comment* and the package also treat triple `~` characters also as code block fences. So when we run `cargo doc`, they will be placed also. <img width="965" alt="image" src="https://user-images.githubusercontent.com/26626194/161208072-5a09a209-57fc-4a52-b190-b0a9be9ffcd6.png"> But `rust-analyzer` doesn't support it so it doesn't have any injected code highlights and any `Run doctest` hint. This pull request tries to allow also them. 🙇🏻♂️ Before: <img width="224" alt="image" src="https://user-images.githubusercontent.com/26626194/161207405-b1d6cfda-82b1-4f60-8e42-c51d0ed98f38.png"> After: <img width="161" alt="image" src="https://user-images.githubusercontent.com/26626194/161207693-8e39997c-9ca6-4e69-8c65-e9b70899f7db.png"> Co-authored-by: Lee Dogeon <dev.moreal@gmail.com>
This commit is contained in:
commit
50225fe630
5 changed files with 21 additions and 7 deletions
|
@ -1,7 +1,7 @@
|
|||
//! Transforms markdown
|
||||
use ide_db::rust_doc::is_rust_fence;
|
||||
|
||||
const RUSTDOC_FENCE: &str = "```";
|
||||
const RUSTDOC_FENCES: [&str; 2] = ["```", "~~~"];
|
||||
|
||||
pub(crate) fn format_docs(src: &str) -> String {
|
||||
let mut processed_lines = Vec::new();
|
||||
|
@ -13,7 +13,8 @@ pub(crate) fn format_docs(src: &str) -> String {
|
|||
continue;
|
||||
}
|
||||
|
||||
if let Some(header) = line.strip_prefix(RUSTDOC_FENCE) {
|
||||
if let Some(header) = RUSTDOC_FENCES.into_iter().find_map(|fence| line.strip_prefix(fence))
|
||||
{
|
||||
in_code_block ^= true;
|
||||
|
||||
if in_code_block {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue