Sublime Forum

Syntax Highlighting for nested objects (html specifically)

#1

When using a textmate theme in sublimetext2 there is no way to highlight or color-code nested objects.

From the TextMate IRC channel, I was told this was a limitation of their rendering engine - which has been fixed in TextMate2.

That being said, will sublimetext2 either support the updated format from TextMate2, or is there a SublimeText2 way of creating syntax highlighting schemes that I cannot find? Or even better - support VIM syntax/color schemes.

0 Likes

#2

+1

this is an ever returning request which i would like to see answered too.

0 Likes

#3

Doesn’t look like anyone is interested, or cares? It would be nice if the author (especially since I am a paying user) would respond.

0 Likes

#4

If I understand the question correctly, nested objects can be highlighted using the include key in a syntax definition.

0 Likes

#5

Hey Nick,

I appreciate the response!

If that holds true, I would be able to have “request.resource_url” highlighted in a different color in SublimeText2:

As it stands, the regex that matches (I’ve tested it), and the resulting selector do not work. Take a look:

		<dict>
			<key>begin</key>
			<string>".*({{(.*)}}).*</string>
			<key>captures</key>
			<dict>
				<key>2</key>
				<dict>
					<key>name</key>
					<string>meta.scope.jinja.variable.html.nested</string>
				</dict>
			</dict>
			<key>end</key>
			<string>"</string>
			<key>name</key>
			<string>meta.scope.jinja.variable.nested.html</string>
		</dict>

I am open to suggestions on how to fix it or approach this!

0 Likes

#6

Are you looking to highlight just the content between the braces?

Seems like a much simpler regex would work:

<dict> <key>name</key> <string>meta.scope.jinja.variable.nested.html</string> <key>match</key> <string>(?&lt;=\{\{)\s*[A-Za-z0-9_\.]+\s*(?=\}\})</string> </dict>

I’d also check that the scope you’ve created isn’t being overwritten by something earlier in the syntax definition.

0 Likes

#7

hello nick,

thanks for addressing this topic. unfortunately the given instruction is a bit over my knowledge. what would one do to have the html-parts of this code highlighted?

[code]

<?php foreach($page->children("limit=10") as $child) { echo "
"; echo "

{$child->project_commission} {$child->title}

{$child->summary}  + Mehr erfahren

"; echo "
"; } ?>[/code]

at the moment only the php-code gets highlighted but not the html snippets.

in general i would also appreciate if the author could be a bit more present in the forum. this is paid software and providing only user support (as much as i appreciate your help) is a bit poor for 60 Dollar software.

this said, thanks in advance for any comment helping me to solve this problem i’ve posted here before https://forum.sublimetext.com/t/syntax-highlighting-for-nested-html/6933/1.

0 Likes

#8

[quote=“nick.”]Are you looking to highlight just the content between the braces?
I’d also check that the scope you’ve created isn’t being overwritten by something earlier in the syntax definition.
[/quote]

I’ll take a look at the regex, thing is I believe that regex exists already. But that being said, I haven’t found a single tutorial on how to check to see it the scopes are overwritten, etc.

0 Likes

#9

A tutorial isn’t really necessary. If the scope you expect isn’t the scope of the text, it’s overwritten.

Suppose I have the following text:

def my_function(): pass

And suppose this is the entire syntax definition:

[code]
name
entity.name.function.python
match
def [A-Za-z0-9_]+\s*(

name my-function.python match def my_function\( [/code]

Q: Which scope gets applied?
A: entity.name.function.python since it comes first in the syntax definition and successfully matches the line.

You can press CTRL+ALT+SHIFT+P to view the scope of any character, or use a plugin like ScopeHunter. The point is, you need to know if your scope is the active for the text.

0 Likes

#10

[quote=“nick.”]A tutorial isn’t really necessary. If the scope you expect isn’t the scope of the text, it’s overwritten.

Suppose I have the following text:

def my_function(): pass

And suppose this is the entire syntax definition:

[code]
name
entity.name.function.python
match
def [A-Za-z0-9_]+\s*(

name my-function.python match def my_function\( [/code]

Q: Which scope gets applied?
A: entity.name.function.python since it comes first in the syntax definition and successfully matches the line.

You can press CTRL+ALT+SHIFT+P to view the scope of any character, or use a plugin like ScopeHunter. The point is, you need to know if your scope is the active for the text.[/quote]

I gathered it wasn’t active at all before that, from using the scope find command.

But what’s interesting to me is, from what you said it’s not a selector at all: e.g. even though one may match more specifically, it’s still “whatever comes first”. Or am I misreading that? So, if I’m reading you correctly, you answered my original question: nested scopes doesn’t work.

I also tried out your regex, feel free to take a look at my files:
gist.github.com/3718188

0 Likes

#11

You are correct that the first matching scope is the one that is applied. But that doesn’t mean nesting doesn’t work.

Suppose we have the following text:

[code]def my_function():
pass

def my_other_function():
pass[/code]

With this syntax definition:

<dict> <key>name</string> <string>entity.name.function.python</string> <key>begin</key> <string>def</key> <key>end</key> <string>:$</string> <key>patterns</key> <array> <dict> <key>name</key> <string>my-function.python</string> <key>match</key> <string>my_function\(</string> </dict> </array> </dict>

Q: What is the scope of my_function?
A: entity.name.function.python and my-function.python, with the styling (color scheme/.tmTheme) going from most specific to least specific.

Q: What is the scope of my_other_function?
A: Just entity.name.function.python

0 Likes