[TxMt] Re: Setting up syntax highlighting for python scripts embedded in xml files

Allan Odgaard mailinglist at textmate.org
Mon Jun 16 04:30:01 UTC 2008


On 15 Jun 2008, at 01:25, Pedja wrote:

> [...] I was trying to set this up for XML so I can have proper  
> syntax highlighting for python. So far, though, I have not had any  
> luck with this. I tried adding the following in the xml language  
> definition, both right after the section for embedded java and, when  
> that didn't work, right after the section for CDATA comments, but it  
> doesn't seem to work:

Adding _after_ the more general rule e.g. for CDATA, when you match  
CDATA, is not going to work. It is the first rule in the grammar which  
matches a construct, which wins.

> { name = 'source.python.embedded.xml';
> 			begin = '<script.*?}>\s*?<!\[CDATA\[';
> 			end = ']]>\s*?<script/>';
> 			beginCaptures = { 0 = { name =  
> 'punctuation.section.embedded.begin.xml'; }; };
> 			endCaptures = { 0 = { name =  
> 'punctuation.section.embedded.end.xml'; }; };
> 			patterns = ( { include = 'source.python'; } );
> },

The patterns are single-line matches. Your script + CDATA is split  
over two lines, so you will have to change strategy to match this,  
i.e. write an outer rule to match <script> with an inner rule to match  
CDATA (if necessary).




More information about the textmate mailing list