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

This is how all code here looks like for me:


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?

4 Likes

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

1 Like

Sure, here is the post

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:

1 Like

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

Here’s what it looks like for me:

VSCode:

GitHub:

Discourse:

StackOverflow:

3 Likes

It’s just highlightjs’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)

5 Likes

Update to Improved syntax highlighting for Julia on the web | Fredrik Ekre ?

1 Like

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

1 Like

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.

@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 :smiley: ). 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.

1 Like

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.

    List of currently enabled languages
    julia
    julia-repl
    bash
    cpp
    cs
    css
    diff
    fortran
    go
    haskell
    http
    ini
    java
    javascript
    json
    llvm
    makefile
    markdown
    mathematica
    matlab
    objectivec
    perl
    php
    python
    r
    ruby
    rust
    sql
    shell
    swift
    tex
    xml
    yaml
    
  • 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 I believe.


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

2 Likes

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

It has not. The major reason is that lookbehind in JS regular expressions is not supported in Safari 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.

2 Likes

Looks like lookbehind is finally coming to Safari, maybe that will help!

1 Like