Vittorio Romeo
Vittorio Romeo

Reputation: 93384

Extending an existing VSCode syntax highlighter with new elements

I am working on a new flavor of Markdown that introduces some new syntactical elements. I have manually modified the markdown.tmLanguage.json file bundled with VSCode to implement some syntax highlighting for them. I would now like to create a VSCode extension that provides the new additions to Markdown's syntax highlighting.

However, I do not really think that copy-pasting the original Markdown syntax highlighting logic just to add a few things on top is a good idea -- is there a way to create a .json syntax highlighting file that inherits (for lack of a better word) the existing syntax highlighting from another file?

For example, here's some pseudocode:

{
    "version": "1.0.0",
    "name": "My Markdown Flavor",
    "extends": "markdown.tmLanguage.json", // <- PSEUDOCODE
    "repository": { "... insert my extensions here ..." }
}

Is that possible? Or do I have to copy-paste the entire markdown.tmLanguage.json file?

Upvotes: 2

Views: 1268

Answers (1)

Vittorio Romeo
Vittorio Romeo

Reputation: 93384

I figured it out -- it is sufficient to include text.html.markdown as the last pattern:

{
    "$schema": "https://raw.githubusercontent.com/martinring/tmlanguage/master/tmlanguage.json",
    "name": "Majsdown",
    "patterns": [
        {
            "include": "#majsdown_inject_expression"
        },
        {
            "include": "#majsdown_execute_statement"
        },
        {
            "include": "text.html.markdown"
        }
    ],
    
    // ...

Upvotes: 3

Related Questions