Categories
Uncategorized

S5 with textile

I’ve started working on a presentation for skillswap. Like any paranoid coder, I want to keep my work under revision control, so I prefer a text based format. Of these, the best option presently seems to be S5. But it does require you to write a fair chunk of HTML. These days though, I prefer textile.

So, I wrote a small standalone textile processor in ruby:

#!/usr/bin/env ruby
require 'rubygems'
require_gem 'RedCloth'
puts RedCloth.new(File.new(ARGV[0]).read).to_html

This, combined with a small Makefile lets me build the S5 presentation quite simply from the textile file.

index.html: s5-head.html vc-intro-svn.txt s5-foot.html
        (cat s5-head.html; 
         ./textile vc-intro-svn.txt; 
         cat s5-foot.html) > $@

The only mildly irritating limitation is that you still have to explicitly wrap the slides in <div class='slide'>...</div>. But I can live with that.

There was still one thing missing though. If you printed out the presentation, all the links wouldn’t show up. Because textile outputs well formed xhtml, it was a simple matter to use a small bit of XSLT to harvest the links on each slide and insert a handout div listing them.

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
  <xsl:output omit-xml-declaration="yes"/>
  <xsl:template match="@* | node()">
    <xsl:copy>
      <xsl:apply-templates select="@* | node()"/>
    </xsl:copy>
  </xsl:template>
  <xsl:template match="div[@class='slide']">
    <div class="slide">
      <xsl:apply-templates/>
      <xsl:if test=".//a">
        <div class="handout">
          <p>Links from the slide:</p>
          <ul>
            <xsl:for-each select=".//a">
              <li>
                <xsl:value-of select="."/>
                <xsl:text>: </xsl:text>
                <a href="{@href}"><xsl:value-of select="@href"/></a>
              </li>
            </xsl:for-each>
          </ul>
        </div>
      </xsl:if>
    </div>
  </xsl:template>
</xsl:stylesheet>

Like all XSLT, it looks more verbose than it actually is (something it shares with Java, IMHO). But it serves a useful purpose. Now, the printed slides aren’t lacking in information.