Home Download Buy Blog Forum Support

Some code highlighting bugs (Javascript)

Some code highlighting bugs (Javascript)

Postby Ko3 on Wed Jan 19, 2011 1:43 pm

Hi there,

I'm new to Sublime Text, which has quite impressed me so far, especialy with its minimap feature and the customization possibilities.

However I came across some little bugs regarding regex matching / code highlighting while I was working on my own web developer ST theme:

Issue 1 (solved (see 2nd post below)).
Sublime Text can't recognise / highlight PHP code when it is placed within a Javascript string. Example:
Code: Select all
<script type="text/javascript" language="JavaScript1.2">
location.href = '<?php echo $_SERVER['PHP_SELF']; ?>';
</script>


Issue 2 (solved (see next post below)).
Script tags don't get recognised as JS code if there is no character placed between start and end script tag.
E. g. this won't get highlighted as JS code, although it should IMO:
Code: Select all
<script type="text/javascript" src="jquery.js"></script>

This however does get highlighted (notice the space between the tags):
Code: Select all
<script type="text/javascript" src="jquery.js"> </script>


Would be nice to see these issues fixed in the next update :)
In the meanwhile, would someone like to help me fix these in the .tmLanguage files (I had no luck so far)?

Ko3
Last edited by Ko3 on Wed Jan 26, 2011 5:53 pm, edited 2 times in total.
Ko3
 
Posts: 7
Joined: Wed Jan 19, 2011 12:11 pm

Re: Some code highlighting bugs (Javascript)

Postby Ko3 on Fri Jan 21, 2011 11:25 am

Ok, here is a solution attempt for issue 2 by modifying line 45 in HTML.tmLanguage:
Code: Select all
<string>(&lt;)([a-zA-Z0-9:]++)(?=[^&gt;]*&gt;&lt;/\2(?&lt;!(?:script))&gt;)</string>


Ko3
Ko3
 
Posts: 7
Joined: Wed Jan 19, 2011 12:11 pm

Re: Some code highlighting bugs (Javascript)

Postby Ko3 on Wed Jan 26, 2011 5:50 pm

Here is fix for issue 1:

Add the following lines right below line 422 in your original JavaScript.tmLanguage file and then add them one more time below line 468:
Code: Select all
<dict>
   <key>begin</key>
   <string>(?=(^\s*)?&lt;\?)</string>
   <key>end</key>
   <string>(?!(^\s*)?&lt;\?)</string>
   <key>patterns</key>
   <array>
      <dict>
         <key>include</key>
         <string>source.php</string>
      </dict>
   </array>
</dict>

...or just download the fixed JavaScript.tmLanguage file from here.

This will fix the problem with PHP code not being captured when it's embedded inside JS quoted strings.

Ko3
Ko3
 
Posts: 7
Joined: Wed Jan 19, 2011 12:11 pm


Return to Technical Support

Who is online

Users browsing this forum: Exabot [Bot], Google [Bot] and 31 guests