Sublime Forum

How can PHP code inside Javascript string be highlighted?

#1

The PHP code within Javascript’s string is not highlighted as PHP syntax. As show in the attached screenshot.
Is is possible to make it correctly highlighted?

0 Likes

#2

It is possible. You would need to either edit the javascript.tmlanguage file and declare a rule that matches <?php (.*) ?> within a string or create a new tmlanguage file that matches strings with php code in it and include the source.js.

The part you want to edit is line 409 to line 474 in Javascript.tmLanguage. Just include the rule for <php tags in both string.quoted.double.js and string.quoted.single.js.

0 Likes

#3

Would anyone mind spelling this out for me?

I’ve opened up javascript.tmlanguage but I’m really not sure how to declare the rule.

Thanks

0 Likes

#4

Anyone got a proper fix for this? I just started using sublime and have been trying to fix this in the language files for hours. Looks like it would be quite a common syntax… N++ handles it just fine

0 Likes

#5

I was going to start using sublime text instead of zend studio today on linux but this stoped me, in my case it was in html though, ¿perhaps they should include this option from scratch in js as well as in html?

0 Likes