diff --git a/docs/theming-guide.adoc b/docs/theming-guide.adoc index 7b01cee6c..ec8d487bd 100644 --- a/docs/theming-guide.adoc +++ b/docs/theming-guide.adoc @@ -3174,6 +3174,71 @@ As a workaround, Asciidoctor PDF inserts a blank page, if necessary, to ensure t You can check on the status of this defect by following https://github.com/asciidoctor/asciidoctor-pdf/issues/95[issue #95]. +== Source Highlighting Theme + +You can define and apply your own source highlighting theme to source blocks when using Rouge as the source highlighter. +This section explains how. + +A custom Rouge theme is defined using a Ruby source file. +Start by creating a Ruby file to define your theme. +Name the file according to the name of your theme and put the file in a folder of your choice (e.g., [.path]_rouge_themes/custom.rb_). +The name of the Ruby class doesn't matter, though it's customary to name it according to the name of the theme as well. + +.rouge_themes/custom.rb +[source,ruby] +---- +module Rouge; module Themes + class Custom < CSSTheme + name 'custom' + + style Comment, fg: '#008800', italic: true + style Error, fg: '#a61717', bg: '#e3d2d2' + style Str, fg: '#0000ff' + style Str::Char, fg: '#800080' + style Num, fg: '#0000ff' + style Keyword, fg: '#000080', bold: true + style Operator::Word, bold: true + style Name::Tag, fg: '#000080', bold: true + style Name::Attribute, fg: '#ff0000' + style Generic::Deleted, fg: '#000000', bg: '#ffdddd', inline_block: true, extend: true + style Generic::Inserted, fg: '#000000', bg: '#ddffdd', inline_block: true, extend: true + style Text, {} + end +end; end +---- + +Each style declaration accepts the following properties: + +* `fg` - sets the foreground (text) color +* `bg` - sets the background color +* `bold` - change the font weight to bold +* `italic` - change the font style to italic +* `underline` - add an underline to the text +* `inline_block` - fill the background color to the height of the line (Asciidoctor PDF only) +* `extend` - extend the background color to the end of the line for a line-oriented match (Asciidoctor PDF only) + +Colors are defined using hexidecimal format (e.g., #ff0000 for red). + +Use the `Text` token to set the background color of the source block and the default text color. + +The complete list of tokens can be found in the https://github.com/jneen/rouge/blob/master/lib/rouge/token.rb[token.rb] file from Rouge. +Refer to the https://github.com/jneen/rouge/tree/master/lib/rouge/themes[bundled themes] to find more examples. + +Once you've defined your theme, you need to enable it use it using the `rouge-style` document attribute, which you specify in the document header or via the Asciidoctor CLI or API. + +[source,asciidoc] +---- +:source-highlighter: rouge +:rouge-style: custom +---- + +Finally, you need to active your theme by requiring the theme file when you invoke Asciidoctor. + + $ asciidoctor -r ./rouge_themes/custom.rb sample.adoc + +You should now see that source code is highlighted to your liking. +For more information about source highlighting with Rouge, refer to the http://rouge.jneen.net/[Rouge project page]. + //// == Resources for Extending Asciidoctor PDF