Message Boards Message Boards


Wolfram Language for the Rogue syntax highlighter

Posted 2 years ago
0 Replies
8 Total Likes

Syntax highlighting for prettifying online or offline code is widely used today. Here on Wolfram community, we use a plugin for the google-code-prettify framework that I initially hacked for Stack Exchange. R Menon worked on a support for the pygments engine which is nice since it can be used with LaTex and various static website generators like Pelican or Jekyll.

A while ago another interesting engine came into existence: A Ruby-based highlighter named Rogue (here on GitHub). It is interesting because it can be used (and seems to become the default) in Jekyll, which is the static website generator behind GitHub pages.

Last night I wrote my first lines of Ruby code and I implemented an initial version that supports Mathematica. If there are any Ruby enthusiasts here that want to take a look at the code, I would be delighted. In essence, it works like the highlighter we have here. One notable difference is that I did not implement the highlighting of pattern variables. I always had mixed feelings when I implemented it back then because, with a lexer based highlighter, it is not possible to really understand the language and highlight things properly. For instance below, every used variable should be green, but this can only be found out by using a real parser:

f[patt : {variable_} /; variable > 0] := {patt, variable}

One of the nice things of the implementation, however, is that no one has to provide a list of built-in symbols anymore. I'm extracting all these from the online Wolfram docs which save a lot of maintaining-time.

I already use the highlighter for my website and you can see it in action for instance here. If you ignore the coloring for the moment (because this is adjusted in CSS), here is the demo page from Rogue for it:



The code can be found on this branch of my fork of Rogue or you can look at the pull request I opened for it here

Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract