Stash Syntax Highlighting

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 votes
Jason Hinch Atlassian Team Aug 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.

Doh!

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

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.

@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.

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.

Jason Hinch Atlassian Team Nov 07, 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).

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?

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

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

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!

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.

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

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?

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

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?

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 Join to answer
Community showcase
Piotr Plewa
Published Dec 27, 2017 in Bitbucket

Recipe: Deploying AWS Lambda functions with Bitbucket Pipelines

Bitbucket Pipelines helps me manage and automate a number of serverless deployments to AWS Lambda and this is how I do it. I'm building Node.js Lambda functions using node-lambda&nbsp...

631 views 0 4
Read article

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot