Skip to content

simonis/asciidoctor-rouge

 
 

Repository files navigation

Asciidoctor Rouge

Build Status Test Coverage Codacy Code quality Gem Version Yard Docs

This project provides an Asciidoctor extension for highlighting source listing blocks using Rouge – a pure-ruby code highlighter that is compatible with pygments.

It supports all Asciidoctor features such as callouts, highlighting of specified lines (attribute highlight), passthroughs inside a code and all other substitutions.

This extension is highly customizable and modular.

Installation

To install (or update to the latest version):

gem install asciidoctor-rouge

or to install the latest development version:

gem install asciidoctor-rouge --pre

Usage

Assign rouge to the source-highlighter attribute in your document’s header or via command-line argument.

asciidoctor -r asciidoctor-rouge -a source-highlighter=rouge Example.adoc

Attributes

You can further customize the source block output with additional Rouge attributes:

rouge-css

Controls what method is used for applying CSS to the tokens. Can be class (CSS classes), style (inline styles) or external (external styles). When class is used, Rouge styles for the specified theme are included in an HTML header. When external is specified, CSS classes are used but no styles will be added except when rouge-theme is not empty in which case its value is interpreted as a URL to a style sheet and a link to that style sheet will be added to the HTML header. Default is class.

rouge-theme

Sets the name of the Rouge colour theme to use. Look into lib/rouge/themes in the Rouge repository for a list of available themes. Default is github.

rouge-style

Alternative name for the rouge-theme for compatibility with asciidoctor-pdf (see #3).

rouge-highlighted-class

CSS class to use on a line wrapper element for highlighted lines. Default is highlighted.

rouge-line-class

CSS class to set on a line wrapper element Default is line.

rouge-line-id

Format string for specifying an HTML id for each line (e.g. with rouge-line-id="L%i" each line of the listing will get an id of the form id="L1", id="L2", etc.). This really only makes sense if the format string is distinct for each source listing, otherwise it will lead to duplicate IDs which makes the generated HTML invalid. Default is no line ids.

Passing CGI-style options for selected language

Rouge allows passing certain options to its Lexer classes when selecting the language to parse. This feature is also available from within Asciidoctor. So instead of simply writing:

[source, console]

to select console as output language (with its default options) you can also write:

[source, "console?prompt=$> "]

This will also select console as output language but it will additionally set the prompt string to $> . Options are comma separeted key=value pairs which are appended to the language string with a ?-character. Consult the various Rouge Lexer classes to find out which additional options they support.

License

This project is licensed under MIT License. For the full text of the license, see the LICENSE file.

About

Rouge code highlighter support for Asciidoctor

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Ruby 100.0%