Stash Syntax Highlighting

Sam Hall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 14, 2013

I followed this in an attempt to enable perl syntax highlighting based on a few additional file extensions...

https://confluence.atlassian.com/display/STASHKB/Configuring+syntax+highlighting+for+file+extensions

So I've added this to the bottom of the stash-config.properties file and restarted stash...

syntax.highlighter.perl.executables=perl
syntax.highlighter.perl.extensions=au_irules,tmpl

But files ending in au_irules and tmpl are not showing any syntax highlighting. Note these files are actually tcl syntax, but I figured it was closest to perl.

2 answers

1 accepted

1 vote
Answer accepted
jhinch _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
August 14, 2013

As mentioned on the knowledge base article this is only available in Stash 2.7 and above. Stash 2.7 has not been released yet but will be within the coming days.

Sam Hall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
August 14, 2013

Doh!

Thanks, looks like I'm all set for when it's released then.

Chris Richardson November 5, 2013

I'm trying to get this working for Java syntax highlighting but to no avail. Can you please provide an example stash-config.properties file?

Mine looks like this, but as you can probably see I'm just guessing at settings:

$ cat ../stash-home/stash-config.properties 
syntax.highlighter.perl.executables=perl
syntax.highlighter.perl.extensions=au_irules,tmpl

syntax.highlighter.java.executables=java
syntax.highlighter.java.extensions=java

syntax.highlighter.javascript.executables=java
syntax.highlighter.javascript.extensions=js

Logs don't show any relevant information. I'm using Stash 2.8.2 on Linux.

Sam Hall
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 6, 2013

@Chris - there's a link to http://highlightjs.org/static/test.html on the Configuring syntax highlighting for file extensions page. There you can see java and js should be already included. How are you verifying that this doesn't work? Some pages don't support syntax highlighting.

You've added my perl extensions, which unless you have perl files ending with au_irules and tmpl extensions isn't going to help you much.

To be honest, I don't fully understand what the syntax.highlighter.<language>.executables option does. Since I wanted to add more files to the perl syntax highlighting, I just copied the perl example and added my file extensions to the extensions option.

Jan Swaelens November 6, 2013

It looks like the highlights are only available when opening files trough the file browser. Not when viewing parts of commits, would be nice though.

jhinch _Atlassian_
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 7, 2013

Stash comes preconfigured and will hightax highlight a large number of files extensions and files which contain an known executable in their hashbang. Generally speaking you should rarely have to modify the default configuration.

Stash only syntax highlights source, not diffs. That means you will not be able to see syntax highlighting in the diff, commits or pull request views as they all render diffs. There is an open feature request for syntax highlighting diffs (STASH-2823).

Kelly Schoenhofen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 5, 2014

Question - Stash may come preconfigured, but how do we see the configuration? A developer brought up that our clojure files ending in .clj aren't being highlighted; looking at the release notes @ highlightjs.org, clojure was added ~18 months ago. Presumably the highlight.js included in Stash would support it; I don't want to blindly add a link to the stash-config.properties file, I'd like to see what extensions you are using for clojure first (since clojure doesn't really support hashbang detection) and then determine if .clj is wrong (on our part) and we should switch to what you're using, or if I should open up a support request to support the standard extension for clojure, or a million different things.

I spent a bunch of time (too much time) picking through the Stash 2.10.1 folder structure looking for clues, this is the closest I came:

var getLanguage = (function () {

        var pattern = /#!(?:\/(?:usr\/)?(?:local\/)?bin\/([^\s]+))(?:\s+([^\s]+))?/;
        var knownLanguages = WRM.data('com.atlassian.stash.stash-web-plugin:source-view.syntax-highlighters') || {};
        var knownExtensions = {
            txt: 'text',
            log: 'text'
        };

but I can't seem to find any configs or anything I can crack open and pick through in an editor.

What can you tell me?

1 vote
cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 6, 2014

Hi Kelly,

The version of highlight.js that we ship at the moment is 7.3. We ship the entire packed highlight file which you should be able to find here:

atlassian-stash/static/lib/highlight/highlight.pack.js

Our default configuration is a little harder to locate, it's stored in the stash-platform.jar:

atlassian-stash/WEB-INF/lib/stash-platformat-$VERSION.jar$stash-default.properties

It looks like Clojure is missing from our default list. I'll add it now to our next release (2.11), but feel free to add it to your own stash-config.properties file for now and it should start working straight away.

syntax.highlighter.clojure.extensions=clj

Cheers,

Charles

Kelly Schoenhofen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 6, 2014

Thanks! I made the change already, and I'll schedule a restart of Stash during planned maintenance later this week.

Alexandre Beaulne January 14, 2014

Hi!

Any ETA as to when Stash will upgrade to version 8.0 of highlight.js? If not, could the upgrade be done on a local Stash server manually?

Thanks!

Adam
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 14, 2014

We're experimenting with libraries other than highlight.js and there's a good chance we'll be moving away from that in the future. So there's no upgrade planned on our end.

You could theoretically do it on your local server by overwriting the highlight.pack.js file (and idea.css) but it's possible things will break. We wouldn't be able to help you with it in Support.

Alexandre Beaulne January 14, 2014

Thanks.

Erlang record access broke highlighting in highlight.js pre-8.0, but has been fixed since:

https://github.com/isagalaev/highlight.js/commit/d462d283ca4449409d8bb49c051aa6d87ef2f173

So if Stash could do syntax highlighting for Erlang in the next release it would make our life easier.

Also relevant: https://jira.atlassian.com/browse/STASH-3883

Kelly Schoenhofen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 14, 2014

Charles, I added the highlighter line for clojure (copy and pasted what you wrote), restarted Stash and .clj files still aren't highlighted. Any ideas? I know you/the docs said we could specify any executable present in the version of Highlighter you ship, which you said was 7.3 and clojure was first added to highlighter.js in 7.1 according to their changelog, but clojure isn't listed here:

https://confluence.atlassian.com/display/STASHKB/Configuring+syntax+highlighting+for+file+extensions

(which may just be an oversight). Are you sure we can specify executables outside that list?

cofarrell
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 14, 2014

Kelly,

Assuming you're running Stash 2.7.0+ that should Just Work. I just double-checked it here and it wasn't working, I add the line to $STASH_HOME/stash-config.properties, restarted and it starts highlighting.

We are talking about the source view here? If you view the source of the source view page you should see a WRM._unparsedData["com.atlassian.stash.stash-web-plugin:source-view.syntax-highlighters"] line up the top, can you see clojure in the set of values?

Yeah don't worry too much about that page - and in fact I should update it with Clojure now.

Cheers,

Charles

Kelly Schoenhofen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 15, 2014

We're on 2.10.1, and it indeed shows up in view source:

\"python\":{\"e\":[\"py\",\"pyw\"],\"x\":[\"python\"]},\"clojure\":{\"e\":[\"clj\"]},\"perl\":{\"e\":[\"pl\",\"pm\"],\"x\":[\"perl\"]},

But no highlighting :(

Maybe a bug with highlighter.js?

Kelly Schoenhofen
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 15, 2014

Ahha, it's a bug with highlighter.js. Any clj file that has a comment at the top it can't deal with. 99% of our clojure scripts have at least one comment at the top. I finally found one that didn't and highlighting worked.

;; example text &lt;-- this breaks highlighting.

Thanks Charles! I'd ask that you either update highlighter.js (and we push them to fix this if it's not already fixed in 8.0) or you switch to something else like you mentioned ;)

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events