Syntax Highlighting

Install a syntax highlighter

To add source highlighting to source blocks, you must have a suitable syntax highlighter available. 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. The use of CodeRay is no longer recommended.

Refer to the table below for instructions on how to install one of these build-time syntax highlighters. If you use Bundler to manage your gems in a Gemfile, add the entry listed in the Bundler column. Otherwise, run the command in the gem command column.

Library gem name Bundler gem command

Rouge

rouge

gem 'rouge'
gem install rouge

Pygments

pygments.rb

gem 'pygments.rb'
gem install pygments.rb

CodeRay

coderay

gem 'coderay'
gem install coderay

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