Sublime Forum

PHP highlight mess

#1

How to fix this? And ST2 doesn’t know where is PHP and where is HTML ?

0 Likes

#2

If you install ScopeHunter via PackageControl it will help you discover the scope for the various parts of your code. Then you can add some of these scopes, and your chosen colours, to your theme-file.

But first I would test a few different themes - this will help to confirm that it is your theme that is letting you down. That is, that your theme isn’t defining colours for the variety of scopes that you would like.

When you are checking the scopes for the various parts of your PHP code, if you believe that some are incorrectly scoped, then it becomes a bit trickier. This would mean that the syntax (PHP.tmLanguage) file is not working correctly - or is not exacting enough. Modifying this file to correct it can be a challenge :frowning:

But perhaps someone, somewhere, has already modified/corrected the PHP syntax file and might offer it to you :wink:

Personally, I added a couple of PHP-specific colours to my theme, but I’m trying to ignore the formatting of PHP/HTML/JS combinations - because I suspect it would prove quite messy to fix.

0 Likes

#3

This might be a mess but I’m happy that I can spot the PHP.


0 Likes

#4

Thanks a lot for the plugin.
I cannot believe, it is so buggy. And nobody cares, as if I am the only one who comes across to these issues in highlighting.

As for php in html attribute. How do you do that? can you share tmLanguage file? :unamused:

0 Likes

#5

I don’t think I’ve touched the PHP syntax file at all, as I recall. But I inserted the following into my theme file:

<dict> <key>name</key> <string>Embedded begin (PHP)</string> <key>scope</key> <string>text.html.basic source.php.embedded.block.html punctuation.section.embedded.begin.php</string> <key>settings</key> <dict> <key>fontStyle</key> <string></string> <key>foreground</key> <string>#FF0000</string> </dict> </dict> <dict> <key>name</key> <string>Embedded end (PHP)</string> <key>scope</key> <string>text.html.basic source.php.embedded.block.html punctuation.section.embedded.end.php</string> <key>settings</key> <dict> <key>fontStyle</key> <string></string> <key>foreground</key> <string>#FF0000</string> </dict> </dict> <dict> <key>name</key> <string>Embedded PHP in HTML double</string> <key>scope</key> <string>text.html.basic meta.tag.inline.any.html string.quoted.double.html source.php.embedded.line.html</string> <key>settings</key> <dict> <key>fontStyle</key> <string></string> <key>foreground</key> <string>#FF0000</string> </dict> </dict> <dict> <key>name</key> <string>Embedded PHP in HTML single</string> <key>scope</key> <string>text.html.basic meta.tag.inline.any.html string.quoted.single.html source.php.embedded.line.html</string> <key>settings</key> <dict> <key>fontStyle</key> <string></string> <key>foreground</key> <string>#FF0000</string> </dict> </dict>
The first two sections - embedded begin and end - refer to the <?php and ?> tags.

Open your theme file (having taken a copy…) and insert the above. I inserted this between scopes ‘support.constant’ and ‘meta.processor.c’, although your theme is unlikely to follow the same order: just insert it *carefully *after all the ‘comment’, ‘keyword’, etc., scopes. Of course, you don’t have to use red :smile:

0 Likes

#6

I suspect someone, somewhere, has managed to fix it. I’m trying not to look at it too closely :unamused: as, although I’m sure it can be fixed, I suspect it’s the sort of challenge whereby, if you fix it in one place, it will be broken elsewhere :astonished:

0 Likes

#7

On reflection, I don’t think the php-syntax file is necessarily broken; it’s just that themes don’t target embedded PHP specifically enough.

Some themes do target specific languages, so it might be worth searching for a more-php centric theme. In the meantime, the following addition to my theme file allows me to target php-functions, but not if they’re embedded within quotes:

<dict> <key>name</key> <string>Embedded PHP in HTML(functions)</string> <key>scope</key> <string>text.html.basic source.php.embedded.block.html support.function</string> <key>settings</key> <dict> <key>fontStyle</key> <string></string> <key>foreground</key> <string>#FFFF00</string> </dict> </dict>

0 Likes