How to extend/modify existing syntax?


I’ve copied(!) the language-xml package and made modifications to it so that cdata sections are treated as Javascript. (I’ve got a number of XML files that contain lots of cdata sections that contain Javascript code.) Obviously, copying the package and modifying it is not the right approach – I should create a new package that defines a new grammar that is similar to the XML grammar except for the differences. But I have no idea how to express that.

So I edited the grammars/xml.cson file to change the scopeName and the name at the top. And then I scrolled down to look for “CDATA” and I saw that it defined a scope name of string.unquoted.cdata.xml for this section. So I changed it to source.js.embedded.xml and added a “patterns” section like this:

'patterns': [
        'include': 'source.js'

That did the trick, but how do I transform this into a grammar that doesn’t copy all the content of the XML grammar?



The last time you asked this question:

I marked it as duplicate of this other topic:

Please keep the related discussions together. Closing this as duplicate as well.

1 Like

closed #3