# Does everyone's code highlight on Discourse look so bland?

**URL:** <https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803>\
**Category:** Meta Discussion\
**Created:** [January 31, 2023, 2:56am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803 "2023-01-31T02:56:12Z")\
**Posts on this page:** 16\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)\
**Post date:** [January 31, 2023, 2:56am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/1 "2023-01-31T02:56:12Z")

</div>

This is how all code here looks like for me:

 ![code](https://global.discourse-cdn.com/julialang/original/3X/2/a/2acf0d5b74180b8bdc12e481e519f4398d4e0e9d.png)  
The `if`, `else`, etc. are bolded, once in a while some words are in blue or red.  
I find it really hard sometimes to parse quickly what am I looking at.

Discourse is said to have highltight.js support and on its website there is a variety of options.  
Is there a setting somewhere that I missed?  
Or is this just how code looks on Julia Discourse?

---

<div class="post-metadata">

**Author:** ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)\
**Post date:** [January 31, 2023, 3:41am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/2 "2023-01-31T03:41:18Z")

</div>

Can you link to the post where you took that screenshot from?

---

<div class="post-metadata">

**Author:** ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)\
**Post date:** [January 31, 2023, 3:48am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/3 "2023-01-31T03:48:30Z")

</div>

Sure, here is the post

> [@Automatic resizing of struct internal array when value changes?](https://discourse.julialang.org/t/automatic-resizing-of-struct-internal-array-when-value-changes/93790/4):
>
> Both getproperty and setproperty! are kind of fiddly to get right, since they inherently rely on constant propagation of the accessed field for their type stability. You can write what you want to achieve like this: function Base.setproperty!(ts::TheStruct, s::Symbol, v) if s === :N setfield!(ts, s, v) arr = getfield(ts, :x) resize!(arr, v) else setfield!(ts, s, v) end end There’s probably a race condition here in multithreaded code. If I may ask,…

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [January 31, 2023, 3:49am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/4 "2023-01-31T03:49:16Z")

</div>

![image](https://global.discourse-cdn.com/julialang/original/3X/3/c/3c08945f3b9f782c369d67f1fbbcb734fe5b40d0.png)

---

<div class="post-metadata">

**Author:** ![goerz](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/goerz/32/3269_2.png) [@goerz](https://discourse.julialang.org/u/goerz)\
**Post date:** [January 31, 2023, 3:59am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/5 "2023-01-31T03:59:10Z")

</div>

That’s what I’m seeing too… It’s never struck me as particularly bland, in particular since there are other highlights that show up in the other code blocks on the linked page: greenish-blue for numbers, red for strings, gray for comments. Looks fine to me. That being said, I’m not sure that I understand what exactly gets highlighted in blue (like `Symbol`)… that seems buggy to me (`TheStruct` should be highlighted the same way).

The specific colors depend on the theme you set in your preferences on Discourse. There could be a few more things that are highlighted (like operators), but there’s just not that much going on in that code snippet. This is how it looks in my text editor:

 ![Screenshot 2023-01-30 at 22.57.47](https://global.discourse-cdn.com/julialang/original/3X/0/0/005b5e1156cb4c723943e9b6e8a2048760b44d16.png)

---

<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:** [January 31, 2023, 4:08am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/6 "2023-01-31T04:08:56Z")

</div>

yeah, on that note, Stackoverflow’s highlight sucks too, we just aren’t popular for people to care

---

<div class="post-metadata">

**Author:** ![uniment](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/uniment/32/24532_2.png) [@uniment](https://discourse.julialang.org/u/uniment)\
**Post date:** [January 31, 2023, 4:23am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/7 "2023-01-31T04:23:12Z")

</div>

Here’s what it looks like for me:

VSCode:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/7/97101d86893cc5d9098abd265413900f07eeca91.png)

GitHub:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/9/3/931eb7b5a575b7c194083a407584bc375f312877.png)

Discourse:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/b/8bb7d3aefb76a613642bf6a892ee6a9c09c26297.png)

StackOverflow:

 ![image](https://global.discourse-cdn.com/julialang/original/3X/e/2/e22105bda6595b2b71040355440105b03ce4ad1f.png)

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [January 31, 2023, 4:23am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/8 "2023-01-31T04:23:34Z")

</div>

It’s just [highlightjs](https://highlightjs.org/static/demo/)’s way of rendering Julia code as far as I understand.

StackOverflow is a wholly different matter and will randomly use highlighting for an unrelated language. (Edit: shameless plug to create a meta account and [vote for Julia’s support here](https://meta.stackexchange.com/questions/355928/julia-syntax-highlighting))

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [January 31, 2023, 7:54am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/9 "2023-01-31T07:54:28Z")

</div>

Update to [Improved syntax highlighting for Julia on the web | Fredrik Ekre](https://fredrikekre.se/posts/highlight-julia/) ?

---

<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:** [January 31, 2023, 8:13am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/10 "2023-01-31T08:13:07Z")

</div>

> [@mbauman](#):
>
> It’s just [highlightjs](https://highlightjs.org/static/demo/)’s way of rendering Julia code as far as I understand.

> [@cormullion](#):
>
> Update to [Improved syntax highlighting for Julia on the web | Fredrik Ekre](https://fredrikekre.se/posts/highlight-julia/) ?

Then why does the highlighting on Discourse look so different from the example (even the “Status Quo” example) in the blog post?

---

<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:** [January 31, 2023, 8:18am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/11 "2023-01-31T08:18:59Z")

</div>

That is probably a color scheme issue. The identification of tokens look like in the status quo of my post, as far as I can see.

---

<div class="post-metadata">

**Author:** ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)\
**Post date:** [January 31, 2023, 6:32pm UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/12 "2023-01-31T18:32:11Z")

</div>

@mbauman It definately is, but when browsing through their website, they don’t seem to fail as much (for anyone looking, Julia is in the premium “misc” category 😃 ). Cliking through their styles, most of the works pretty fine.  
I have Monokai set up in VSCode, would like to make some tweaks to it, if I had time, but it makes stuff much clearer.

@cormullion and @fredrikekre looks great to me. not sure if there shouldn’t maybe be a vote for a style to put on Discourse. But basically anything would be better then the current minimal highlight.  
Does the custom highlight.js schemes work in VSCode? I would be nice to try it out.

---

<div class="post-metadata">

**Author:** ![mbauman](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mbauman/32/31082_2.png) [@mbauman](https://discourse.julialang.org/u/mbauman)\
**Post date:** [January 31, 2023, 7:22pm UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/13 "2023-01-31T19:22:46Z")

</div>

To my knowledge, Fredrik’s branch has not (yet) been upstreamed into highlights.js. It’d be great if it could!

Just to be clear, the things we have control over on Discourse are:

- The default highlighting language — this is set to `julia`

- The enabled highlighting languages — this is set to 33 languages and we can add more if you find it’d be helpful.

- I think the themes’ CSS should be able to override the default styling of the identifiers. This doesn’t change _which_ identifiers and syntaxes are highlighted, but it changes _how_ they are highlighted. The defaults are here pulled from [code\_highlighting.scss](https://github.com/discourse/discourse/blob/85971a8b677c90271f5b0c581952f181f5ee618f/app/assets/stylesheets/common/base/code_highlighting.scss) I believe.

* * *

All of this is completely unrelated to how VS Code does its highlighting, which is powered by TextMate grammars.

---

<div class="post-metadata">

**Author:** ![mkoculak](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkoculak/32/28310_2.png) [@mkoculak](https://discourse.julialang.org/u/mkoculak)\
**Post date:** [January 31, 2023, 7:32pm UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/14 "2023-01-31T19:32:17Z")

</div>

Ok, yeah - thanks for clearing that up.

I was thinking that discourse gives you access to highlight.js options and admins can choose the style to go with etc.  
The thing is, I tried other languages that came to my mind and all of them have the same problem.  
But from the link it would seem that Discourse in general picks a handful of tokens to highlight for all languages and that’s it.  
Do I get it right?

Yeah, I know that it is unrelated to VSC, was just curious if anyone here tried using highlight.js there. (quick googling doesn’t show any extensions for that, so probably not possible).

---

<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:** [January 31, 2023, 9:16pm UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/15 "2023-01-31T21:16:28Z")

</div>

> [@mbauman](#):
>
> To my knowledge, Fredrik’s branch has not (yet) been upstreamed into highlights.js. It’d be great if it could!

It has not. The major reason is that [lookbehind in JS regular expressions is not supported in Safari](https://caniuse.com/js-regexp-lookbehind) so my branch would not be merged upstream. Probably some of the changes can still be merged, but since my branch can be used with Documenter without upstream support this is not something high on my TODO list.

---

<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:** [February 17, 2023, 1:03am UTC](https://discourse.julialang.org/t/does-everyones-code-highlight-on-discourse-look-so-bland/93803/16 "2023-02-17T01:03:07Z")

</div>

Looks like [lookbehind is finally coming to Safari](https://developer.apple.com/documentation/safari-release-notes/safari-16_4-release-notes), maybe that will help!
