Allow file paths ending in a language-specific-extension to be used as the language name for injections (#12368)

This allows us to detect the language from the extension if we use paths
in fenced code blocks.

Release Notes:

- You can now use file paths ending in a language-specific file
extension at the start of markdown code blocks.
This commit is contained in:
Nathan Sobo 2024-08-22 19:02:49 -06:00 committed by GitHub
parent db4ff7da6b
commit 88b03bc074
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 24 additions and 16 deletions

View file

@ -214,9 +214,9 @@ fn test_dynamic_language_injection(cx: &mut AppContext) {
],
);
// Replace Rust with Ruby in code block.
// Replace `rs` with a path to ending in `.rb` in code block.
let macro_name_range = range_for_text(&buffer, "rs");
buffer.edit([(macro_name_range, "ruby")]);
buffer.edit([(macro_name_range, "foo/bar/baz.rb")]);
syntax_map.interpolate(&buffer);
syntax_map.reparse(markdown.clone(), &buffer);
syntax_map.reparse(markdown_inline.clone(), &buffer);
@ -232,7 +232,7 @@ fn test_dynamic_language_injection(cx: &mut AppContext) {
);
// Replace Ruby with a language that hasn't been loaded yet.
let macro_name_range = range_for_text(&buffer, "ruby");
let macro_name_range = range_for_text(&buffer, "foo/bar/baz.rb");
buffer.edit([(macro_name_range, "html")]);
syntax_map.interpolate(&buffer);
syntax_map.reparse(markdown.clone(), &buffer);