The Rexx Highlighter is a child project of the Rexx Parser. Developed around a common code base, it currently includes output drivers for three modes: HTML, ANSI terminals emulators, and (Lua)LaTeX.
~~~rexx
Say "Done!" -- Inform the user
~~~
Say "Done!" -- Inform the user
The figure above shows the HTML highlighter in action, or, to be more precise, the effect of a Rexx fenced code block in a Markdown file.
Irrespective of the mode, the highlighter works against a set of CSS files, an optional style patch system, and a mapping that assigns HTML classes to every element category and subcategory. The actual highlighting is taken care of by an extensible system of drivers.
The highlighter is distributed with an extensible system of CSS stylessheets. These stylesheets have to use a limited subset of CSS, as, although they are directly used by the HTML highlighter (i.e., by web browsers), they are interpreted in by the ANSI and LaTeX drivers.
You can read about the supported level of CSS and the interpretation process here.
Two samples are provided: rexx-light.css, a
light grey background one (currently incomplete), and the default style,
rexx-dark.css,
a dark background one.
Say "Done!" -- Inform the user
Dark background
Say "Done!" -- Inform the user
Light grey background
Starting with release 0.3a, the Rexx Highlighter includes an
additional collection of dark and light styles, inspired by the vim
color files distributed with the vim
editor:
| Vim dark styles | Vim light styles |
|---|---|
| rexx-vim-dark-blue.css | rexx-vim-light-delek.css |
| rexx-vim-dark-darkblue.cssĀ | rexx-vim-light-morning.css |
| rexx-vim-dark-desert.css | rexx-vim-light-peachpuff.css |
| rexx-vim-dark-elflord.css | rexx-vim-light-shine.css |
| rexx-vim-dark-evening.css | rexx-vim-light-zellner.css |
| rexx-vim-dark-industry.css | |
| rexx-vim-dark-koehler.css | |
| rexx-vim-dark-murphy.css | |
| rexx-vim-dark-pablo.css | |
| rexx-vim-dark-ron.css | |
| rexx-vim-dark-slate.css | |
| rexx-vim-dark-torte.css |
These files have been kindly curated and adapted by Rony Flatscher (thanks!). You can take a look at the whole palette of predefined styles here (as of 20251227).
You can select a style by using the style= attribute on
a Rexx fenced code block, or the
--style= option of the highlight utility. The Highlighter class class also
allows to specify a style in the options argument.
You can also take a look at our Highlighter torture test and use the style dropdown to see most of the capabilities of all styles in action.
The style patch system allows one-time, simple and easy patching of a CSS style.
Say "Done!" -- Inform the user
Standard highlighting
Say "Done!" -- Inform the user
With patch="all comments yellow"
Style patches can be specified by using the patch=
attribute of a Rexx fenced code block,
or the --patch= option of the highlight utility. The parse method
of the Highlighter class also
accepts an optional style patch
argument.
The Rexx Parser assigns a category to all the elements in a program, and, in the case of taken constants (i.e., syntactical constructs which are specified to be strings or symbols that are taken as a constant), it also assigns a subcategory.
The HTMLClasses routine creates a mapping between element categories and subcategories and HTML classes. The mapping provided by HTMLClasses is reductive: it assigns the same HTML class to several, different, element categories or subcategories. For example, all special and operator characters are assigned the same HTML class. This is so because, in normal circumstances, you will neither need nor desire to highlight, say, parentheses and the plus sign using different colors. There may be cases, though (for instance, some teaching contexts), where such a discrimination may be useful or interesting. In these cases, you can write your own version of HTMLClasses (and prepare the corresponding CSS files), or simply use the style patch system and temporarily patch the highlighting styles.
Actual highlighting is taken care of by an extensible system of drivers, for HTML, ANSI Terminals, and (Lua)LaTeX. Each driver encapsulates the specificities of an output format.
Highlighter.cls - A
Highlighter instance is created
by supplying the class with a program source array and a stem containing
options. The parse method takes an optional style patch as an
argument, and it returns the source program, highlighted according to
the supplied options and patches.FencedCode.cls - A highly configurable routine that processes
Markdown-style Rexx fenced code blocks and highlights them using the
Rexx Parser.StylePatch.cls
- An abstraction defining a way to
apply style patches to defined highlighting styles.HTMLClasses.cls - A program that assigns HTML classes to element
categories and taken constant names.