Sublime Forum

Some code highlighting bugs (Javascript)

#1

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:

<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:

<script type="text/javascript" src="jquery.js"></script>

This however does get highlighted (notice the space between the tags):

<script type="text/javascript" src="jquery.js"> </script>

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

Ko3

0 Likes

#2

Ok, here is a solution attempt for issue 2 by modifying line 45 in HTML.tmLanguage:

<string>(&lt;)([a-zA-Z0-9:]++)(?=^&gt;]*&gt;&lt;/\2(?&lt;!(?:script))&gt;)</string>

Ko3

0 Likes

#3

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:

<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

0 Likes