To activate highlight.js, add the following attribute entry to the header of your AsciiDoc file:
Load support for additional languages
To load additional languages supported by highlight.js, list them in the value of the
highlightjs-languages document attribute.
Separate each language by a comma followed by an optional space.
The common highlight.js bundle does not include support for Rust and Swift.
Let’s set the
highlightjs-languages attribute so the HTML converter loads support for them into the HTML page.
:source-highlighter: highlight.js :highlightjs-languages: rust, swift
highlightjs-languages attribute only applies when generating a standalone HTML document (i.e., backend: html, standalone: true).
It does not work when generating embedded HTML, which is used by site generator integrations such as Antora.
Use a custom highlight.js library
If you’d rather use a personal copy of highlight.js instead of the one hosted on the CDN, follow these steps:
Create your custom bundle on the download page.
Download and unpack the zip into a folder called highlight adjacent to your AsciiDoc file (or in the output directory, if different)
Rename highlight/highlight.pack.js to highlight/highlight.min.js
Rename highlight/styles/github.css to highlight/styles/github.min.css
githubwith the name of the
highlightjs-themeyou are using, if different.
Add the attribute entry
:highlightjsdir: highlightto the header of your AsciiDoc file.
Alternatively, you can pass the
-a highlightjsdir=highlightflag when invoking the Asciidoctor CLI.
The output file will use your personal copy of the highlight.js library and stylesheet instead of the one hosted on cdnjs.