How to Enable Syntax Highlighting in Code Examples - Fluid Topics - How To

Fluid Topics
How To
Target Audience

How to Enable Syntax Highlighting in Code Examples

Business need

Code samples included in published content are easier to read if syntax is properly highlighted.

Overview of the solution

This can be achieved by using a JavaScript customization tool such as the dedicated code library HighlightJS.

Adding custom JavaScript code to a tenant requires relevant technical skills and remains under the responsibility of the customer. Antidot will not support this code and cannot be held responsible for any service malfunction related to JavaScript customization.


Custom JavaScript code must be provided to Fluid Topics Customer Service team so that it can be added to a test portal and then deployed to production.


Below is an example of code syntax highlighting on FT Doc Example

The Fluid Topics Doc Team chose the HighlightJS library to highlight code syntax.

Since the HTML tags including code samples in Fluid Topics documentation are pre.codeblock p and pre.codeblock, the following JavaScript code has been added to the doc portal:

var hljsScript = document.createElement('script');
hljsScript.src = '';
hljsScript.async = true;

var hljsStyle = document.createElement('link');
hljsStyle.href = '';
hljsStyle.rel = "stylesheet";

document.addEventListener('ft:reader:topicsloaded', function(event){
    document.querySelectorAll('pre.codeblock p, pre.codeblock').forEach((block) => {