'How to create VSCode syntax highlighting config for YAML strings
I’m looking for the same thing as Markdown code blocks syntax highlighting, but for YAML string values mapped to specific keys.
More detailed explanation:
I’d like to create a syntax highlighting configuration for my own file extension, let’s say .foo.
The format of .foo files is the same as YAML, except that I want certain keys to contain string values that, when opened in vscode, are highlighted using the syntax highlighting config for a different language. This is the same as if I opened a Markdown file and started writing a code block for a different language.
For example, in the snippet below,
bar: |
## My Heading
- [ ] item
baz: This is an ordinary string.
The string stored in bar would use syntax highlighting for Markdown (or RMarkdown), but the string mapped to baz would be highlighted as a string, no different from the behavior I would get by opening a YAML file.
The non-YAML highlighting would be applied to bar, but not baz, whether or not I use a multiline string.
I don’t want to apply this syntax highlighting to all YAML files; ideally, I would have a separate syntax highlighting extension specifically for my .foo extension, but based on the YAML highlighting.
I don’t need to be able to specify which language the strings use from within a given .foo file, but I would like to be able to select which keys’ string values are highlighted using a certain language in the syntax highlighting configuration for all .foo files.
I've looked at this question and this question, but I'm having trouble getting injection grammars to work, especially when it comes to tying the grammar to a specific key.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
