Fix Markdown code rendering in tooltips ignoring languages (#10607)
Some code blocks that are returned in tooltips (returned by language servers, for example) use the language file extension as the language in the the triple-backtick code blocks. Example: ```rs fn rust_code() {} ``` ```cpp fn rust_code() {} ``` Before this change we only looked up the language with the `rs`/`cpp`/... being interpreted as the language name. Now we also treat it as a possible file extension. Release Notes: - Fixed Markdown code blocks in tooltips not having correct language highlighting. Before:  After:  Co-authored-by: Bennet <bennetbo@gmx.de>
This commit is contained in:
parent
c834ea75ef
commit
7e1a184446
1 changed files with 33 additions and 1 deletions
|
@ -252,7 +252,7 @@ pub async fn parse_markdown_block(
|
|||
new_paragraph(text, &mut list_stack);
|
||||
current_language = if let CodeBlockKind::Fenced(language) = kind {
|
||||
language_registry
|
||||
.language_for_name(language.as_ref())
|
||||
.language_for_name_or_extension(language.as_ref())
|
||||
.await
|
||||
.ok()
|
||||
} else {
|
||||
|
@ -360,3 +360,35 @@ pub fn new_paragraph(text: &mut String, list_stack: &mut Vec<(Option<u64>, bool)
|
|||
text.push_str(" ");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
|
||||
#[test]
|
||||
fn test_dividers() {
|
||||
let input = r#"
|
||||
### instance-method `format`
|
||||
|
||||
---
|
||||
→ `void`
|
||||
Parameters:
|
||||
- `const int &`
|
||||
- `const std::tm &`
|
||||
- `int & dest`
|
||||
|
||||
---
|
||||
```cpp
|
||||
// In my_formatter_flag
|
||||
public: void format(const int &, const std::tm &, int &dest)
|
||||
```
|
||||
"#;
|
||||
|
||||
let mut options = pulldown_cmark::Options::all();
|
||||
options.remove(pulldown_cmark::Options::ENABLE_YAML_STYLE_METADATA_BLOCKS);
|
||||
|
||||
let parser = pulldown_cmark::Parser::new_ext(input, options);
|
||||
for event in parser.into_iter() {
|
||||
println!("{:?}", event);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue