Improved syntax highlighting for Julia on the web

Hello everyone, I made some improvements to the Julia syntax highlighter in highlight.js. This library is used by Documenter.jl, Franklin.jl, this discourse forum and many other tools to highlight Julia code, so hopefully it will be useful. I wrote a post about it for anyone interested:

Comments and suggestions welcome!



Great work! I would love to see these changes one day added to Chroma, which is used by Hugo. Its Julia highlighting is really underwhelming compared to this.


This is is a great post and a great effort, also the StarWarsArray code is hilarious!


If this is upstreamed, it would improve a lot of user-facing code since Stackoverflow recently moved to using highlight.js


Nice work! Thank you! Is there any chance these highlights can be reproduced in other environments, like julia-vim , or jlcode?

Thanks, I knew I read about some forum switching, but couldn’t find which one when trying to find it. I did include StackOverflow in the post, just didn’t know it was so recent.

Probably. In particular contextual type highlighting is something that I have wanted in vim. I opened an issue:

1 Like

Is this an improvement to the support or the first time it is supported? According to this:
there is no support for Julia at all.

It would be great to get this on stackoverflow, since right now the syntax highlighting isn’t just bad – it’s worse than nothing. It’s probably using a highlighter from a completely different language, Matlab perhaps.

It is an improvement; highlight.js it is used by many tools for julia code already, just doesn’t tag as much. I don’t know why it isn’t on that list though, probably just an oversight.

If I understand correctly it has to be on that list to be deployed by stackoverflow

If your post doesn’t have the correct highlighting, it’s possible it’s not supported. Please look at the list of supported languages. If your language is not on the list, it needs to be created within the highlight.js project before it can be deployed by Stack Exchange.

This would be a huge improvement.

Okay, I submitted, let’s see what they say.


Yeah, the last I heard Stack Overflow was just using the default, language agnostic highlighter for Julia code. There were some posts on Meta about it.

EDIT: Of course that was before they switched to highlight.js.

The Julia REPL highlighting is particularly bad right now on Stack Overflow.

Great work, thanks!

In the C example, the function arguments are colored differently than the types, is it possible to also get that in Julia (with your improvements arguments and types have the same color)?

That is because the C highlighter mark int and char as keyword. If you look at the Julia example you see that the argument is tagged with params and the argument types as type. The fact that they look the same in my improved example is just that the specific color scheme assigns the same color to params and type.


This PR is now merged, and I asked for StackExchange to enable Julia syntax highlighting here: Julia syntax highlighting - Meta Stack Exchange


How can one add this to a Franklin.jl site now? Is it more realistic to just wait until highlight.js tags a new version or should I add this manually to the page (I saw that the default version pulls it in via node)

It is very easy; replace the file _libs/highlight/highlight.js with the one I provided and either make sure you use optimize(...; prerender=false) such that this new version is used when you deploy too, or you tell Franklin to prerender with the new file by setting Franklin.HIGHLIGHTJS[] = "/path/to/new/highlight.js".


Thank you!

Just to make this more prominent:

Please Upvote!


this probably needs some contrib as well.


Thank you for the great effort to improve highlighting!

Now, I found some lexing errors, where should I send the feedbacks?

For example:

I appreciate your swift fix.