Search code examples
sublimetext3syntax-highlightingsublimetext

Can I Append Custom Highlights to an Existing Syntax Without Forking It?


I'm looking to add a few custom syntax highlights to an existing one, but I don't want to maintain a copy of the base one I'm using in its entirety. Is there a way to extend an existing syntax (and continue to do so through updating, if possible) and just append a few new rules to it?

I've tried using extends: Packages/HTML/HTML.sublime-syntax in my own .sublime-syntax file, but I get a console error for "syntax inheritance does not allow for mixed versions" and I have no idea what that means. I don't see it mentioned in the documentation either. Help?


Solution

  • The Documentation on Syntax Definitions has a section on inheritance and how you do it; there a section on Limitations:

    A syntax may extend a syntax that itself extends another syntax. There are no enforced limits on extending, other than that all syntaxes must share the same version.

    version is a new concept in recent versions of Syntaxes; it's listed under compatibility. The general gist is that there are various things about syntaxes which are either bugs or unexpected/undesirable behaviour, but since there are so many syntaxes already available that would be broken if that behaviour was changed, the concept of version was added so that newer syntaxes can avail themselves of fixes.

    As a result, as mentioned above all syntaxes must be the same version, ostensibly so that their behaviour is consistent. Syntaxes that are newly rewritten/revamped in Sublime Text 4 use the new version, and the HTML syntax is one of them.

    Hence, you need to include version: 2 in your syntax to be able to extend the HTML syntax.