Syntax Highlighting

Install a syntax highlighter

To add source highlighting to source blocks, you must have a suitable syntax highlighter installed. Asciidoctor PDF performs source highlighting during conversion, which means you must use a build-time syntax highlighter.

The build-time syntax highlighters that Asciidoctor PDF supports out of the box are Rouge, Pygments, and CodeRay. Rouge is the preferred syntax highlighter.

To install Rouge, Pygments, or CodeRay, run the corresponding gem command shown below.

$ gem install rouge
$ gem install pygments.rb
$ gem install coderay

Alternately, you can declare the gem in your Gemfile to manage it using Bundler.

Activate syntax highlighting

Once you’ve installed a syntax highlighter, you need to activate it for a given document by setting the source-highlighter attribute in the document header and assigning it the keyword value of the applicable library.

= Document Title
:source-highlighter: rouge