$ gem install coderay
CodeRay is an encoding-aware, syntax highlighter that supports the languages listed below.
C |
C++ |
Clojure |
CSS |
Delphi |
diff |
ERB |
Go |
Groovy |
HAML |
HTML |
Java |
JavaScript |
JSON |
Lua |
PHP |
Python |
Ruby |
Sass |
SQL |
Taskpaper |
XML |
YAML |
To use CodeRay with Asciidoctor, you need the coderay gem. You can use one of the following methods to install CodeRay.
$ gem install coderay
$ sudo apt-get install ruby-coderay
$ sudo dnf install rubygem-coderay
Once you’ve installed the gem, assign the coderay value to the source-highlighter attribute in the document header to activate it.
:source-highlighter: coderay
You can further customize the source block output with additional CodeRay attributes.
Controls what method is used for applying CSS to the tokens.
Can be class or style.
Default: class.
Controls how line numbers are laid out.
Can be table or inline.
If line wrapping is enabled on preformatted blocks (i.e., prewrap), and you want to use line numbering on source blocks, you must set the value of this attribute to inline in order for the numbers to line up properly with their target lines.
Default: table.
:source-highlighter: coderay
:coderay-linenums-mode: inline
[%linenums,ruby]
----
ORDERED_LIST_KEYWORDS = {
'loweralpha' => 'a',
'lowerroman' => 'i',
'upperalpha' => 'A',
'upperroman' => 'I'
#'lowergreek' => 'a'
#'arabic' => '1'
#'decimal' => '1'
}
----
See the CodeRay stylesheet section to learn about the coderay-css attribute.