# Syntax Highlighting in Discourse?

**URL:** <https://racket.discourse.group/t/syntax-highlighting-in-discourse/240>\
**Category:** Site Feedback\
**Created:** [November 23, 2021, 10:51pm UTC](https://racket.discourse.group/t/syntax-highlighting-in-discourse/240 "2021-11-23T22:51:43Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![simonls](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/simonls/32/170_2.png) [@simonls](https://racket.discourse.group/u/simonls)\
**Post date:** [November 23, 2021, 10:51pm UTC](https://racket.discourse.group/t/syntax-highlighting-in-discourse/240/1 "2021-11-23T22:51:44Z")

</div>

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

````
```racket
#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`:

```bash
#!/bin/bash
# A simple script
ls
NAME="simon"
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](https://www.sitepoint.com/community/t/discourse-syntax-highlighter-does-anyone-know-what-it-is/116932)

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](https://github.com/discourse/discourse/blob/1472e47aae5bfdfb6fd9abfe89beb186c751f514/app/controllers/highlight_js_controller.rb#L14)  
So there indeed seems to be a site setting for the highlighted languages.

[highlight js demo](https://highlightjs.org/static/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?

---

<div class="post-metadata">

**Author:** ![spdegabrielle](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/spdegabrielle/32/95_2.png) [@spdegabrielle](https://racket.discourse.group/u/spdegabrielle)\
**Post date:** [November 24, 2021, 8:49am UTC](https://racket.discourse.group/t/syntax-highlighting-in-discourse/240/2 "2021-11-24T08:49:14Z")

</div>

I’ve forked highlight.js and started adding racket identifiers to a copy of [scheme.js](https://github.com/spdegabrielle/highlight.js/blob/main/src/languages/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

[http://pasterack.org/pastes/86700](http://pasterack.org/pastes/86700)  
gives an error in the discourse preview  
 ![image](https://global.discourse-cdn.com/free1/uploads/racket/original/1X/37d922968cbcccf1ff0d69ffd4f877ad17cb4d67.png)

> <https://github.com/stchang/pasterack/issues/70#issuecomment-971901705>
>
> https://racket.discourse.group/t/link-preview-did-not-render-for-twitch-racket-l…ivestream-link/96/3?u=spdegabrielle
> 
> error on Discourse when discourse attempts to render a preview from pasterack: 
> \> oEmbed / OpenGraph tags could not be found: description, image
> 
> \- https://oembed.com
> \- https://ogp.me
> 
> Might be fun to see if I can get http://pasterack.org/pastes/29314 to render code + fish
> 
> I think I need to mess with these lines: https://github.com/stchang/pasterack/blob/1e4e2cc31e873044e76e329d42761363a9875fa2/pasterack.rkt#L709
> 
> 
> (assign to me if you like)

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:

> [@Syntax coloring (was: First Post)](https://racket.discourse.group/t/syntax-coloring-was-first-post/20/5):
>
> It supports scheme, via [highlight.js](https://highlightjs.org/), which does not support Racket.

```scheme
#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)

```

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [November 28, 2021, 10:43pm UTC](https://racket.discourse.group/t/syntax-highlighting-in-discourse/240/3 "2021-11-28T22:43:46Z")

</div>

abcd

```scheme
(define x 19)

```

```scheme
(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.

---

<div class="post-metadata">

**Author:** ![jbclements](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/jbclements/32/11_2.png) [@jbclements](https://racket.discourse.group/u/jbclements)\
**Post date:** [November 28, 2021, 10:55pm UTC](https://racket.discourse.group/t/syntax-highlighting-in-discourse/240/4 "2021-11-28T22:55:20Z")

</div>

ooh, what about the #lang line?

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

#|abcd otuh
oethun
|#

```

Not bad. It supports more than I expected.
