Code formatting and Syntax highlighting

In the forum editor it’s impossible to enter code with syntax highlighting. You can’t enter three backticks to open or close a code fence and even single backticks behave really weird. Not optimal for a forum about coding.

It must be some kind of setting in Discourse since code formatting and sytax highlighting work fine in other Discourse-based forum.

To use syntax highlighting in discourse use a backtick (only one) in the beginning and the end of the text.

your code or text here

How it looks in the editor

@Megha Single back ticks don’t do synax highlighting and don’t allow for multi-line code snippets. In other Discourse forums I’m active in, triple backticks optionally followed by the language activate syntax highlighting.

Here we seem to have to use tildes instead:

using (var file = new FileStream("cookies.txt", FileMode.Open))

Is rendered as

using (var file = new FileStream("cookies.txt", FileMode.Open))

I’m OK with either backticks or tildes but the respective toolbar button should format the code appropriately or we would end up with the same code dumps as in the old forum.


Thanks for this - I know it’s an old post but I was searching for awhile for it, didn’t come up in any of the searches I tried on the forum. TIL the term “code fence”.

Is there a section in the forum for proper usage that these instructions could be posted to? It’s a much better solution than users doing screenshots or pasting unformatted code into their questions.

Aaaaand I just discovered the “site feedback” threads… i’ll catch on eventually :wink: