# Improved syntax highlighting for Julia on the web

**URL:** https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149
**Category:** Community
**Tags:** blog, blog-post
**Created:** [October 27, 2020, 9:13pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149 "2020-10-27T21:13:02Z")
**Posts on this page:** 20
**Page:** 1

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [October 27, 2020, 9:13pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/1 "2020-10-27T21:13:02Z")

</div>

Hello everyone, I made some improvements to the Julia syntax highlighter in [highlight.js](https://github.com/highlightjs/highlight.js). This library is used by [Documenter.jl](https://github.com/JuliaDocs/Documenter.jl), [Franklin.jl](https://github.com/tlienart/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:

> **[Improved syntax highlighting for Julia on the web | Fredrik Ekre](https://fredrikekre.se/posts/highlight-julia/)**
>
> A greatly improved syntax highlighter for the Julia programming language in highlight.js.

Comments and suggestions welcome!

/Fredrik

---

<div class="post-metadata">

### Author: ![christopher-dG](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/christopher-dg/32/7387_2.png) [@christopher-dG](https://discourse.julialang.org/u/christopher-dG)
#### Post date: [October 27, 2020, 9:58pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/2 "2020-10-27T21:58:24Z")

</div>

Great work! I would love to see these changes one day added to [Chroma](https://github.com/alecthomas/chroma), which is used by Hugo. Its Julia highlighting is really underwhelming compared to this.

---

<div class="post-metadata">

### Author: ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)
#### Post date: [October 28, 2020, 7:21am UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/3 "2020-10-28T07:21:10Z")

</div>

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

---

<div class="post-metadata">

### Author: ![Alec\_Loudenback](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alec_loudenback/32/278_2.png) [@Alec\_Loudenback](https://discourse.julialang.org/u/Alec_Loudenback)
#### Post date: [October 28, 2020, 10:46am UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/4 "2020-10-28T10:46:42Z")

</div>

If this is upstreamed, it would improve a lot of user-facing code since Stackoverflow [recently moved to using highlight.js](https://meta.stackexchange.com/questions/353983/goodbye-prettify-hello-highlight-js-swapping-out-our-syntax-highlighter)

---

<div class="post-metadata">

### Author: ![lmiq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lmiq/32/18314_2.png) [@lmiq](https://discourse.julialang.org/u/lmiq)
#### Post date: [October 28, 2020, 10:51am UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/5 "2020-10-28T10:51:20Z")

</div>

Nice work! Thank you! Is there any chance these highlights can be reproduced in other environments, like [`julia-vim`](https://github.com/JuliaEditorSupport/julia-vim) , or [`jlcode`](https://github.com/wg030/jlcode)?

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [October 28, 2020, 12:01pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/6 "2020-10-28T12:01:10Z")

</div>

> [@Alec\_Loudenback](#):
>
> If this is upstreamed, it would improve a lot of user-facing code since Stackoverflow [recently moved to using highlight.js](https://meta.stackexchange.com/questions/353983/goodbye-prettify-hello-highlight-js-swapping-out-our-syntax-highlighter)

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.

> [@lmiq](#):
>
> Nice work! Thank you! Is there any chance these highlights can be reproduced in other environments, like [`julia-vim`](https://github.com/JuliaEditorSupport/julia-vim) , or [`jlcode`](https://github.com/wg030/jlcode)?

Probably. In particular contextual type highlighting is something that I have wanted in vim. I opened an issue: [Contextual highlighting of types · Issue #216 · JuliaEditorSupport/julia-vim · GitHub](https://github.com/JuliaEditorSupport/julia-vim/issues/216)

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [October 28, 2020, 12:13pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/7 "2020-10-28T12:13:24Z")

</div>

> [@fredrikekre](#):
>
> I made some improvements to the Julia syntax highlighter in highlight.js

Is this an improvement to the support or the first time it is supported? According to this: [https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED\_LANGUAGES.md](https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md)  
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.

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [October 28, 2020, 12:22pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/8 "2020-10-28T12:22:04Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![DNF](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dnf/32/10191_2.png) [@DNF](https://discourse.julialang.org/u/DNF)
#### Post date: [October 28, 2020, 12:31pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/9 "2020-10-28T12:31:13Z")

</div>

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

> <https://meta.stackoverflow.com/questions/274371/what-is-syntax-highlighting-and-how-does-it-work>

> If your post doesn’t have the correct highlighting, it’s possible it’s not supported. Please look at the [list of supported languages](https://github.com/highlightjs/highlight.js/blob/master/SUPPORTED_LANGUAGES.md). 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.

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [October 28, 2020, 12:40pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/10 "2020-10-28T12:40:06Z")

</div>

Okay, I submitted [https://github.com/highlightjs/highlight.js/pull/2797](https://github.com/highlightjs/highlight.js/pull/2797), let’s see what they say.

---

<div class="post-metadata">

### Author: ![CameronBieganek](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cameronbieganek/32/6915_2.png) [@CameronBieganek](https://discourse.julialang.org/u/CameronBieganek)
#### Post date: [October 28, 2020, 12:51pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/11 "2020-10-28T12:51:53Z")

</div>

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.

---

<div class="post-metadata">

### Author: ![jebej](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jebej/32/1784_2.png) [@jebej](https://discourse.julialang.org/u/jebej)
#### Post date: [October 28, 2020, 1:09pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/12 "2020-10-28T13:09:34Z")

</div>

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)?

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [October 28, 2020, 1:18pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/13 "2020-10-28T13:18:11Z")

</div>

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`](https://github.com/highlightjs/highlight.js/blob/f58ea7117ef8d2764551ee183ab6b363503a7787/src/styles/gruvbox-dark.css#L39-L45).

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [October 28, 2020, 10:26pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/14 "2020-10-28T22:26:35Z")

</div>

> [@fredrikekre](#):
>
> Okay, I submitted [https://github.com/highlightjs/highlight.js/pull/2797](https://github.com/highlightjs/highlight.js/pull/2797), let’s see what they say.

This PR is now merged, and I asked for StackExchange to enable Julia syntax highlighting here: [Julia syntax highlighting - Meta Stack Exchange](https://meta.stackexchange.com/questions/355928/julia-syntax-highlighting)

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [October 29, 2020, 4:14pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/15 "2020-10-29T16:14:42Z")

</div>

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)

---

<div class="post-metadata">

### Author: ![fredrikekre](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fredrikekre/32/1688_2.png) [@fredrikekre](https://discourse.julialang.org/u/fredrikekre)
#### Post date: [October 29, 2020, 4:51pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/16 "2020-10-29T16:51:10Z")

</div>

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"`.

---

<div class="post-metadata">

### Author: ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)
#### Post date: [October 29, 2020, 5:26pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/17 "2020-10-29T17:26:50Z")

</div>

Thank you!

---

<div class="post-metadata">

### Author: ![laborg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laborg/32/5474_2.png) [@laborg](https://discourse.julialang.org/u/laborg)
#### Post date: [October 30, 2020, 10:22am UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/18 "2020-10-30T10:22:19Z")

</div>

Just to make this more prominent:

# Please Upvote!

> <https://meta.stackexchange.com/questions/355928/julia-syntax-highlighting>

---

<div class="post-metadata">

### Author: ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)
#### Post date: [November 3, 2020, 12:42am UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/19 "2020-11-03T00:42:13Z")

</div>

[https://github.com/codemirror/CodeMirror/tree/master/mode/julia](https://github.com/codemirror/CodeMirror/tree/master/mode/julia)

this probably [needs](https://github.com/codemirror/CodeMirror/issues/6459) some contrib as well.

---

<div class="post-metadata">

### Author: ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)
#### Post date: [November 6, 2020, 12:58pm UTC](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149/20 "2020-11-06T12:58:01Z")

</div>

Thank you for the great effort to improve highlighting!

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

For example:

> **[Public API · Documenter.jl](https://documenter.juliadocs.org/v0.25/lib/public/)**
>
> Documentation for Documenter.jl.

 ![highlightjs](https://global.discourse-cdn.com/julialang/original/3X/3/4/343389418925c5cb9652c47e0af9af5e33679d1b.png)

**Edit:**  
I appreciate your swift [fix](https://github.com/fredrikekre/highlight.js/issues/2).

[Next page](https://discourse.julialang.org/t/improved-syntax-highlighting-for-julia-on-the-web/49149.md?page=2)
