The Rexx Highlighter
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.
Architecture
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.
CSS
The highlighter is distributed with an extensible system of
CSS styles. 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
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.
The style patch system
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.
From element categories to HTML classes
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.
Drivers
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.
Documentation
- Highlighter documentation, including:
Included software
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.
Utilities
- Highlight - A sample utility program that highlights Markdown, HTML, Rexx and LaTeX files.