How to enable automatic code syntax highlighting?

In theme settings, enable Code Highlighting to style code added to rich text editors with the appropriate HTML tags

From Theme Settings → Styling → Code Highlighting check the box to Enable:

theme-settings-code-highlighting-enable

Once enabled, select the Languages you want to use:

code-highlighting-languages-setting


Full list of available code languages for code highlighting.

Only select the languages you plan to use, adding too many languages can impact page performance.

Choose a Color Scheme:

code-highlighting-color-scheme-light-dark

Decide whether to include Line Numbers which displays line numbers on the left-hand side of the code:

code-highlighting-line-numbers-copy-code

Select Copy Code to add a small copy button on the top right corner of the code block.

The copy button appears on hover for code blocks and doesn't apply to inline styles.

How to add inline code styling

inline-code-syntax-highlighting

If you want to add highlight code within a paragraph, from the rich text editor, click more then choose Code Format:

rich-text-code-format

This will add the HTML code tag to allow the syntax highlighting to be applied.

Click Advanced → Source Code to see the tag applied. You can also manually code the tags here as well:

source-code-with-code-format-html-tag

These languages will be detected automatically:

  • JavaScript

  • C

  • C++

  • Python

  • Java

  • HTML

  • CSS

  • Ruby

  • Go

  • PHP

  • JSON

For any other language, you need to add the corresponding language class to the code tag in the Source Code editor.

Here is an example of how to add the language class to the code tag:

and looks like this:

objective-c-code-language-class-example

How to add code blocks

examples-automatic-code-syntax-highlighting

To add code blocks with syntax highlighting, the HTML pre tag has to be added.

From the rich text editor, change the style (usually says paragraph) to Pre:

Screenshot 2023-05-26 at 4.04.23 PM

Then add the Code Format:

code-format-pre-html-tags

In the rich text editor, it looks like this:

code-style-rich-text-editor

In the Source Code, it looks like this:

source-code-syntax-highlighting-html-tags

Follow the steps outlined above ↑ to add the language class if it is not one of the languages listed that are detected automatically.