🇨🇳 Code syntax highlighting

Discourse natively supports syntax highlighting, using highlight.js by default.

If your code isn’t highlighting correctly, you can force the language you want to use within the code block, like this:

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

Which renders as:

3.times do |stuff|
  stuff.do
end

The language you set must be available on the platform. You can check the language settings on your Discourse site by looking at the highlighted_languages configuration option.

If your posts still don’t display correctly, you’ll need to contact your site administrator.

Discourse usually displays syntax highlighting with its default installation.

No Syntax Highlighting

If you don’t want any syntax highlighting for your code, you can type the characters “text” after the code block:

``` text
Your text to NOT highlight here
```
Your text to NOT highlight here

As shown above.

Please refer to the original article iSharkFly - 飞鲨 for more information.

Thanks to the official support.

3 Likes