This guide explains how to configure which programming languages are available for syntax highlighting in Discourse.
Required user level: Administrator
Syntax highlighting enhances readability in code blocks by applying formatting based on the programming language. You can customize the languages available for syntax highlighting in Discourse.
Configuring the highlighted_languages site setting
To configure the list of programming languages for syntax highlighting:
Navigate to the Admin panel.
Go to Settings.
Search for the highlighted_languages site setting.
In this setting, you can define which languages will be available for syntax highlighting. Enter the names of the languages you want to support, separated by commas.
Adding support for additional languages
If your desired language is not bundled with highlight.js, you need to add it manually. Below are the steps to achieve this:
Locate a module for your language: Find a highlight.js module that supports the language you want to add. For example, to add Solidity, you can use the highlightjs-solidity package.
I’m not sure how to do this. I’ve added it to the discourse settings. Is it going to find the package for me and take care of everything, or do I have to put this extra javascript package somewhere? I’ll appreciate some guidance
Bump. If we want to add syntax highlighting support for languages not already in highlight.js, is there any way to add this directly eg via a theme component, or do we need to get the upstream highlight.js people to accept a PR with the additional syntax?
I’m asking as there is an fairly esoteric pair of languages Archetype Description Language (ADL) and Archetype Query Language (AQL) which the owners of discourse.openehr.org would like to be syntax highlight-able. They have technical capability to build a parser/highlighter, they just need to know how to make it work in a Discourse.
In the last week or two, I’ve noticed that the code highlighting doesn’t seem to be registering when it should. See here for an example. When I specify a language (java in the case above), it will apply the colors.
Here is another example for XML:
We have dozens of languages to be detected. I see the subtext under this setting says that too many can cause it to perform poorly, but I don’t think we added anything recently.