Home Download Buy Blog Forum Support

Syntax Highlighting for nested objects (html specifically)

Syntax Highlighting for nested objects (html specifically)

Postby chris.george on Wed Aug 29, 2012 5:18 pm

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.
Last edited by chris.george on Sat Sep 01, 2012 2:24 am, edited 1 time in total.
chris.george
 
Posts: 7
Joined: Mon Aug 13, 2012 3:29 pm

Re: Syntax Highlighting for nested objects (html specifically)

Postby totoff on Thu Aug 30, 2012 7:36 am

+1

this is an ever returning request which i would like to see answered too.
totoff
 
Posts: 9
Joined: Sat Mar 17, 2012 4:49 pm

Re: Syntax Highlighting for nested objects (html specifically)

Postby chris.george on Tue Sep 04, 2012 2:59 pm

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.
chris.george
 
Posts: 7
Joined: Mon Aug 13, 2012 3:29 pm

Re: Syntax Highlighting for nested objects (html specifically)

Postby nick. on Tue Sep 04, 2012 10:59 pm

If I understand the question correctly, nested objects can be highlighted using the include key in a syntax definition.
nick.
 
Posts: 266
Joined: Wed Jan 18, 2012 3:45 am

Re: Syntax Highlighting for nested objects (html specifically)

Postby chris.george on Fri Sep 07, 2012 2:43 pm

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


As it stands, the regex that matches (I've tested it), and the resulting selector do not work. Take a look:
Code: Select all
      <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!
chris.george
 
Posts: 7
Joined: Mon Aug 13, 2012 3:29 pm

Re: Syntax Highlighting for nested objects (html specifically)

Postby nick. on Sat Sep 08, 2012 2:54 am

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

Seems like a much simpler regex would work:
Code: Select all
<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.
nick.
 
Posts: 266
Joined: Wed Jan 18, 2012 3:45 am

Re: Syntax Highlighting for nested objects (html specifically)

Postby totoff on Mon Sep 10, 2012 1:47 pm

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: Select all
           
<?php
foreach($page->children("limit=10") as $child) {
echo "<div class='project teaser'>";
echo "<p class='meta'><a href='{$child->url}'>{$child->project_commission}&nbsp;{$child->title}</a></p>
<p class='summary'>{$child->summary}&nbsp;<a href='{$child->url}' title='{$child->title}'>&nbsp;+&nbsp;Mehr erfahren</a></p>";
echo "</div>";
}
?>


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 http://www.sublimetext.com/forum/viewtopic.php?f=3&t=8787.
totoff
 
Posts: 9
Joined: Sat Mar 17, 2012 4:49 pm

Re: Syntax Highlighting for nested objects (html specifically)

Postby chris.george on Tue Sep 11, 2012 6:55 pm

nick. wrote: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.



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.
chris.george
 
Posts: 7
Joined: Mon Aug 13, 2012 3:29 pm

Re: Syntax Highlighting for nested objects (html specifically)

Postby nick. on Wed Sep 12, 2012 1:37 pm

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:
Code: Select all
def my_function():
    pass


And suppose this is the entire syntax definition:
Code: Select all
<dict>
    <key>name</string>
    <string>entity.name.function.python</string>
    <key>match</key>
    <string>def [A-Za-z0-9_]+\s*\(</string>
</dict>

<dict>
    <key>name</string>
    <string>my-function.python</string>
    <key>match</key>
    <string>def my_function\(</string>
</dict>


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.
nick.
 
Posts: 266
Joined: Wed Jan 18, 2012 3:45 am

Re: Syntax Highlighting for nested objects (html specifically)

Postby chris.george on Thu Sep 13, 2012 10:34 pm

nick. wrote: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:
Code: Select all
def my_function():
    pass


And suppose this is the entire syntax definition:
Code: Select all
<dict>
    <key>name</string>
    <string>entity.name.function.python</string>
    <key>match</key>
    <string>def [A-Za-z0-9_]+\s*\(</string>
</dict>

<dict>
    <key>name</string>
    <string>my-function.python</string>
    <key>match</key>
    <string>def my_function\(</string>
</dict>


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.



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:
https://gist.github.com/3718188
chris.george
 
Posts: 7
Joined: Mon Aug 13, 2012 3:29 pm

Next

Return to Technical Support

Who is online

Users browsing this forum: Google [Bot], Yahoo [Bot] and 13 guests