ShowOff is great if you are fed up with the bloated presentation applications that make a mess of your source code. Text files means that presentations can be properly version controlled. It’s easy to re-arrange slides and sections. ShowOff uses SHJS to highlight code blocks. It supports many languages, but currently not Clojure. Searching around for a while revealed a Gist of SHJS styling code that I wanted to try out:
# Clojure syntax highlighting for GNU source-highlight # rocks with SHJS comment start ";" include "number.lang" vardef SPECIALCHAR = '.' environment string delim """ """ begin specialchar = $SPECIALCHAR end type = "int|byte|boolean|char|long|float|double|short|void" vardef FUNCTION = '(([[:alpha:]]|_)[[:word:]]*(?=[[:blank:]]*)' function = $FUNCTION include "symbols.lang"
This is what I did on my MacOSX Snow Leopard to get ShowOff to high-light Clojure source code:
1. Install some pre-requisites. I use HomeBrew, but you can use MacPorts or whatever package manager you prefer.
gem install showoff brew install yuicompressor brew install source-highlight brew install unix2dos
2. Download the shjs source distro.
3. Unzip shjs-0.6-src.zip somewhere which we will call SHJS_HOME
4. cd SHJS_HOME
5. touch source-highlight-lang/clojure.lang
6. Edit source-highlight-lang/clojure.lang and paste this Clojure source code high-lighting spec (that’s the same as displayed above).
7. My Perl installation needed a recursive descent parser, so I did this:
cpan install Parse::RecDescent
cp lang/sh_clojure.min.js ~/.rvm/gems/ruby-1.9.2-p290/gems/showoff-0.4.2/public/js/sh_lang/
Should you discover that you need some more tools installed, you can clean up with
make maintainer-clean. After you installed whatever you were missing, run
Testing Clojure high-lighting
In order to test this, we will create a simple presentation called “mypres”:
showoff init mypres
This creates a new directory
mypres. We go to that directory and look around:
. ├── one │ └── 01_slide.md └── showoff.json
OK, so we have now the skeleton of a presentation, containing a section folder named
one and a set of slides in the
01_slide.md file. Looking closer at that file, we see this:
!SLIDE # My Presentation # !SLIDE bullets incremental # Bullet Points # * first point * second point * third point
We will now add to this file a slide definition with some Clojure source code, formatted as a code block by indenting it. Note that we have preceded the code with
@@@ clojure, in order to tell ShowOff what language we want to format the block as:
!SLIDE encode-symbol # Huffman encoding # @@@ clojure (defn encode "takes as arguments a message and a tree and produces the list of bits that gives the encoded message" [[first & rest :as message] tree] (when (seq message) (concat (encode-symbol first tree) (encode rest tree))))
We serve the presentation:
$ showoff serve
Finally we can watch the presentation by browsing to http://localhost:9090