Sublime Forum

Syntax Highlighting Bug

#1

Hey Guys,
I’m a developer of phpBB3 styles. Recently i switched to Sublime and noticed following bug. In phpBB3 there are simple conditionals which are used mainly in head and body area. Sublime seems to recognize it wrong. See my screenshot:

karolorzel.com/files/screens … 172008.jpg

As you can see. After the phpBB3 Conditional syntax is broken. Sublime seems to interpret phpBB3 conditionals as html comments. Never had any troubles with other editors. Any possibility to fix that ? It makes phpBB3 templating almost impossible. I’m attaching the example file.
example.html.zip (522 Bytes)

0 Likes

#2

Have you tried setting the syntax to HTML?

HTML usually provides PHP syntax highlighting as well, and properly handles HTML comment blocks. It might not highlight the conditional statement, but it will not break the HTML highlighting. The conditional statement will just look like a comment.

0 Likes

#3

Yes. I tried that just to be sure. Result is the same… :frowning:

0 Likes

#4

Yeah, it appears that the syntax highlighting does not pick up on the html comment syntax inside the style block or script blocks. It could be added though, maybe I will take a look later.

0 Likes

#5

You can try this. I just inserted the code below in the HTML tmLanguage file under the embedded javascript and css. This would have to be done for all embedded languages. Probably in a cleaner fashion where it is defined once, and each embedded language includes it.

<dict> <key>begin</key> <string>&lt;!--</string> <key>captures</key> <dict> <key>0</key> <dict> <key>name</key> <string>punctuation.definition.comment.html</string> </dict> </dict> <key>end</key> <string>--\s*&gt;</string> <key>name</key> <string>comment.block.html</string> <key>patterns</key> <array> <dict> <key>match</key> <string>--</string> <key>name</key> <string>invalid.illegal.bad-comments-or-CDATA.html</string> </dict> <dict> <key>include</key> <string>#embedded-code</string> </dict> </array> </dict>

You can try out the file here HTML.tmLanguage.zip (2.98 KB)

It should work okay for css and javascript at least.

0 Likes

#6

It works :smile: at least partially. If I do something like that:

<!-- IF DEFAULT_PHPBB3_CONDITIONAL_STATEMENT -->
	body {font-size: {SOME_DEFINED_FONTSIZE}px;}
<!-- ENDIF -->

(just added {SOME_DEFINED_FONTSIZE} )

then it’s broken again…

0 Likes

#7

Yeah. In order to make it really work well, I might have to descend into the CSS tmLanguage since the HTML language just includes the rules for CSS form the CSS.tmLanguage file. The CSS.tmLanguage isn’t designed to expect such things.

That is really how the HTML is doing the embedded code. It is literally just including the scripting language’s tmLanguage file. There might be a way to make the the scripts recognize the defines as such without altering the included languages, but I would have to spend quite a bit more time analyzing the dynamics of the rules and figuring out how to insert the new rules to be picked up. It is pretty easy targeting the comments because they are so different than the syntax of most languages.

I am not used to using these kinds of defines; therefore I don’t really know all of their rules and usage at this time, so it is hard for me to really put something together at this time.

0 Likes

#8

ok :smile: Thanks for your help and further explanation. I really appreciate it :smile:

0 Likes