Previews of our custom Rouge lexers and themes for the ALAN Docs project, and other ALAN-related documentation.
Warning
|
Currently we only have the ALAN lexer, and a single theme. In the future this document we’ll also cover the other required lexers (BNF) and ALAN themes ("tutorial" and "lib"). |
Warning
|
WIP THEMES! — The CSS themes are still incomplete, I need to:
|
A basic ALAN IF code sample, shown in all available theme variations.
Here some sample of advanced AsciiDoc features and how they’re rendered for each theme.
Every beverage IsA object -- (1) (2)
Is drinkable. -- (3)
End every.
-
beverage
is the new class. -
object
is the parent class. -
The
drinkable
attribute is used by thedrink
verb.
Every beverage IsA object -- (1) (2)
Is drinkable. -- (3)
End every.
-
beverage
is the new class. -
object
is the parent class. -
The
drinkable
attribute is used by thedrink
verb.
Every beverage IsA object -- (1) (2)
Is drinkable. -- (3)
End every.
-
beverage
is the new class. -
object
is the parent class. -
The
drinkable
attribute is used by thedrink
verb.
Specific code selections can be styled as if marked via a highlighter pen, using the #..#
and [green]#..#
notations for yellow and green, which will wrap their in content in <mark>
and <span class="green">
, respectively.
Warning
|
It looks like using This is going to affect the ALAN Beginner’s Guide, which heavily relies on this feature; so probably we can’t use Rouge for that publication. |
Every beverage IsA object -- yellow marker
Is drinkable. -- green marker
End every.
Every beverage IsA object -- yellow marker
Is drinkable. -- green marker
End every.
Every beverage IsA object -- yellow marker
Is drinkable. -- green marker
End every.
Here we’ll have a closer look at specific syntax elements, and how they are rendered (or hidden) by the various CSS themes for ALAN code.
Here’s how strings and their delimiters, along with escapes and interpolations are rendered across themes:
Say "You carefully inspect $+1; it surely doesn't resemble
any other $01 you've ever seen, $!1 features are unique.
$p$iYou tell Bob ""This $1 might be what we were looking for""."
Say "You carefully inspect $+1; it surely doesn't resemble
any other $01 you've ever seen, $!1 features are unique.
$p$iYou tell Bob ""This $1 might be what we were looking for""."
Say "You carefully inspect $+1; it surely doesn't resemble
any other $01 you've ever seen, $!1 features are unique.
$p$iYou tell Bob ""This $1 might be what we were looking for""."
ALAN’s “special characters combinations” are captured as either escape sequences or interpolations by our Rouge lexer.
We capture as escape sequences those special characters groups which are substituted by some fixed literal character (including ""
):
"$$ $_ $i $n $p $t """
"$$ $_ $i $n $p $t """
"$$ $_ $i $n $p $t """
We capture as interpolations those special characters groups which are substituted by some dynamic game-reference:
"$1 $+2 $03 $-1 $!2 $a $l $o $v"
"$1 $+2 $03 $-1 $!2 $a $l $o $v"
"$1 $+2 $03 $-1 $!2 $a $l $o $v"
Note
|
The way these special characters are grouped in the ALAN Manual differs from the way they are treated by our lexer. The official documentation doesn’t classify them as either escapes or interpolations, and they are presented in two separate groups based on whether they refer to Our approach here is different, for we’re trying to classify them as tokens, according to their nature. The closest token types that I could come up with (and which are supported by Rouge) are escape sequences and interpolations, which seem to represent their behaviour fairly accurately. |
ALAN uses quoted IDs (instead of strings) to hand file names following import
, play
and show
.
The Rouge ALAN lexer will capture as single-quoted strings quoted IDs representing files names, and capture their enclosing '
as a single-quote string delimiter.
IMPORT 'StdLib/library.i'.
PLAY 'mmedia\music.aiff'.
SHOW 'mmedia\picture.jpeg'.
IMPORT 'StdLib/library.i'.
PLAY 'mmedia\music.aiff'.
SHOW 'mmedia\picture.jpeg'.
IMPORT 'StdLib/library.i'.
PLAY 'mmedia\music.aiff'.
SHOW 'mmedia\picture.jpeg'.
Code blocks for languages not covered by our custom CSS will fallback to use the native Rouge theme defined via the :rouge-style:
attribute.
Example, using the thankful_eyes
theme:
link:custom-rouge-adapter.rb[role=include]
Note
|
If no theme is specified via :rouge-style: , Asciidoctor will default to the github theme.
|
Asciidoctor will convert the native Rouge theme to CSS and inject it in its default CSS stylesheet, which won’t interfere with out custom styles and themes.
This is quite convenient, for it ensures that code examples from other languages are also highlighted (i.e. if Rouge has a lexer for that language), and authors of a document are free to choose their fallback theme of choice.
The names of the currently available native Rouge themes are:
base16
|
Default base16 theme. |
bw
|
A port of Pygment’s “Black and White” theme. |
colorful
|
A port of Pygment’s “Colorful” theme. |
github
|
“GitHub” theme. |
gruvbox
|
Based on the “gruvbox” theme. |
igorpro
|
“Igor Pro”. |
magritte
|
“Magritte”. |
molokai
|
A “Monokai” variation. |
monokai.sublime
|
“Monokai Sublime”, a Monokai variation inspired by Sublime Text. |
monokai
|
“Monokai” classic. |
pastie
|
A port of Pygment’s “Pastie” theme. |
thankful_eyes
|
Thankful Eyes. |
tulip
|
Tulip. |