Sublime Forum

I want to create syntax highlighting for Silverstripe CMS

#1

Hi, my names Steve. I am new here, so if I am posting in the wrong section please forgive me and let me know!

I use a CMS called SilverStipe - silverstripe.org/ - and I think it’s great. You should check it out, especially the new version 3 beta! Looks great!

However, it uses it’s own templating language and file extension which is .ss . The theme I am using at the moment (Solarized) doesn’t do a very good job so I wanted to created whatever is needed to get it right. It will be very similar to how PHP is in HTML so I don’t think it will be very difficult.

Could someone help me with what I will need to do to do this for happen?

Cheers,
Steve

0 Likes

Custom Syntax Highlight question
How to extend an already existing tmLanguge
#2

If you’re a developer yourself, creating a syntax is not difficult. Basically it’s just a lot of regex’s and an understanding of the scope taxonomy. The SilverStripe templating docs will be useful. Here is documentation on syntax in Sublime, and this is the corresponding page for Textmate (from which Sublime derives it’s syntax features).

For a templating system, it shouldn’t be too difficult. I’m in the process of building a Perl syntax from scratch, and that’s a bit more complex. :smile:

0 Likes

#3

Thanks, thats a real help!

I have started to create one but I’m not worrying about the patterns and snippets yet. Just wanted it to look the same as HTML to start with (including colour of the tags etc) so made a real simple one. Below is the JSON and the buiult XML tmLanguage code for what I have so far:

{ "name": "SilverStripe Templates", "scopeName": "text.html.ss", "fileTypes": "ss"], "patterns": ], "uuid": "461239ff-321d-4b44-bc63-6f8a7d6bce4a" }

and the built XML:

[code]<?xml version="1.0" encoding="UTF-8"?>

fileTypes ss name SilverStripe Templates patterns scopeName text.html.ss uuid 461239ff-321d-4b44-bc63-6f8a7d6bce4a [/code]

However, when I restart SublimeText 2 and make a new .ss file it doesn’t use any of the same colouring and HTML. Am I missing something, or misunderstanding scopes?

0 Likes

#4

You haven’t defined any scopes of value. “text.html” is like a last-resort scope, and most schemes probably won’t define it (except to define “text” or “source”). A better way would be to include the HTML syntax:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
    <plist version="1.0">
    <dict>
       <key>fileTypes</key>
       <array>
          <string>ss</string>
       </array>
       <key>name</key>
       <string>SilverStripe Templates</string>
       <key>patterns</key>
       <array>
              <dict>
                     <key>include</key>
                     <string>text.html</string>
              </dict>
       </array>
       <key>scopeName</key>
       <string>source.ss</string>
       <key>uuid</key>
       <string>461239ff-321d-4b44-bc63-6f8a7d6bce4a</string>
    </dict>
    </plist>

That way you get all the scopes defined by the HTML.tmLanguage file.

But what you really should be doing is an edit to the HTML.tmLanguage file to include SilverStripe specific syntax. So you might add:

<dict>
       <key>contentName</key>
       <string>embedded.source.ss</string>
       <key>begin</key>
       <string>&lt;%</string>
       <key>end</string>
       <string>%&gt;</string>
       <key>patterns</key>
       <array>
              <dict>
                     <key>include</key>
                     <string>source.ss</string>
              </dict>
       </array>
</dict>

Then in the SilverStripe.tmLanguage, you only have to worry about the SilverStripe syntax.

0 Likes

#5

Thanks again nick.

I’ve copied your code into my file and it doesn’t work. Also added it the the JSON and re built it but that didn’t work. I’ve been following what is in the docs:

[quote]Select Json to tmLanguage in Tools | Build System
Press F7
A .tmLanguage file will be generated for you in the same folder as your .JSON-tmLanguage file
Restart Sublime Text so all your changes can take effect[/quote]

Also, what you suggested goes against what the TextMate docs seem to be saying:

I can’t find anything in the docs about “include” though

Any ideas?

Cheers

0 Likes

#6

In the code I provided, change “text.html” to “text.html.basic” . My mistake.

The include key is documented better on the Textmate resouce. Basically it allows you to pull in another syntax, items from the repository of the current syntax, or the entire current syntax itself. It’s really powerful.

As to scope naming, if you look in the default HTML.tmLanguage file, you’ll see that php is included as “source.php” . That is pulling in the full PHP language, so it’s a bit different than SS’s templating language. I assumed that it was possible to insert arbitrary PHP alongside the SS template, which may not be correct. In any case, I think you’ll be fine naming the scope either “text.html.ss” or “source.ss” . I do think my previous post’s latter suggestion is the way to go though, since this we’re dealing with an HTML file with embedded PHP, not the other way around.*

  • Okay, it actually is the other way around since it will be handled server side by PHP. But it LOOKS like an HTML file for the most part, so I think it’s easier to treat it as such.
0 Likes

#7

Thats brilliant! Got it working a treat!

It also seems that most of the stuff is already working, such as the <% %> stuff which is great!

Bellow is the code for anyone to use:

{ "name": "SilverStripe Templates", "scopeName": "source.ss", "fileTypes": "ss"], "patterns": { "include": "text.html.basic" }], "uuid": "461239ff-321d-4b44-bc63-6f8a7d6bce4a" }

Thanks nick, You’ve been a real help

0 Likes

#8

For those stumbling in from Google, I’ve created a ST2 package for SilverStripe templates, with syntax highlighting and snippets. Install via Package Control or via the github repo: http://bit.ly/UueqnL

0 Likes