How do I select a language in code blocks?

Is there a way to suggest a <code> highlighting language in a Discourse post? SE uses a magic HTML comment; that mechanism doesn’t appear to work in Discourse.


Summary:

When using triple backticks to enclose code blocks, you can type a language name after the first set of backticks:

E.g.

``` ruby
3.times do |stuff|
  stuff.do
end
```

Result:

3.times do |stuff|
  stuff.do
end

The highlighted_languages site setting allows you to specify which languages can have syntax highlighting rules.

Discourse uses highlight.js for syntax highlighting.

5 Likes