Syntax Highlighting in Discourse?

While writing another post I tried to use github style markdown like:

#lang racket
(define test 5)

getting this without any syntax highlighting

#lang racket
(define test 5)

so lets try scheme?

(define test 5)

lets try bash:

# A simple script
echo "how are you $NAME"

so that works...

Searching a bit I found this link Discourse Syntax Highlighter - does anyone know what it is? - Community - SitePoint Forums | Web Development & Design Community

One of the comments says that discourse might configure the set of languages to a small subset by default.
With further search I found: discourse/highlight_js_controller.rb at 1472e47aae5bfdfb6fd9abfe89beb186c751f514 · discourse/discourse · GitHub
So there indeed seems to be a site setting for the highlighted languages.

highlight js demo > lisp : it seems the closest builtin is scheme
With rackets #lang ... it is probably very difficult to get syntax highlighting in external tools like highlight.js.

Maybe people who have worked on language server things and adding syntax highlighting to editors other than drracket, have some insights about what could be at least be approximated?

The more I think about it, it seems very difficult to add highlighting properly, maybe having only basic highlighting only for #lang racket would already be useful?

But I haven't found anything that would suggest, that this can be simply configured somewhere while keeping the hosting. Maybe there is something in the settings that allows to add some custom javascript or something, that could add another lang to highlight.js?

Anyways enabling scheme might be a good start?

I’ve forked highlight.js and started adding racket identifiers to a copy of scheme.js that I’ve named racket.js

Not uploaded my changes yet because I’m only up to fixnums in the racket reference

Was only planning on identifiers - so it will still break on Racket specific syntax - so if anyone feels like picking something’s racket specific it would be a help.

I feel like handling #lang xxx yyy/zzz would be a sufficient start.

Another option is to use a pastebin that embeds in discourse posts or enhance pasterack to do the same with oEmbed
gives an error in the discourse preview

The GitHub embed above is both an example and a pointer to where I am up to - but I won’t be moving forward on this.

Previous notes:

#lang racket/gui

(define my-language 'English)

(define translations
  #hash([English . "Hello world"]
        [French . "Bonjour le monde"]
        [German . "Hallo Welt"]
        [Greek . "Γειά σου, κόσμε"]
        [Portuguese . "Olá mundo"]
        [Spanish . "Hola mundo"]
        [Thai . "สวัสดีชาวโลก"]))

(define my-hello-world
  (hash-ref translations my-language
            "hello world"))

(message-box "" my-hello-world)
1 Like


(define x 19)
(define x 19)

Ah! Okay. I had set scheme to be the default language highlight... but I had failed to add scheme to the list of legal highlight choices. Seems like there could be a warning about that, sigh... Ah well.

1 Like

ooh, what about the #lang line?

#lang racket
(define x 19)
"aoeunth ; this should not end the string"
but actually it does (define x 3)

#|abcd  otuh

Not bad. It supports more than I expected.