/talkode

Output colorized ruby code in rtf format given a range of git commits.

Primary LanguagePython

Talkode

Syntax highlighting in your presentations.

Talkode provides several tools to simplify highlighting and colorizing syntax in presentations.

colorize.sh

Synopsis

colorize.sh FILE1 [FILE2, …]

Description

colorize.sh batch colorizes Ruby and JavaScript files.

Given a file in Ruby or JavaScript with either the .rb or .js extension, colorize.sh will colorize the file and output it as an RTF document. It will optionally upload the file to Google Drive if you have the gdrive Google Drive CLI client installed and configured. (Details below)

Google Drive support

colorize.sh supports Google Drive uploads via the gdrive CLI client.

  • Put the appropriate binary of the gdrive CLI tool in your path as gdrive.
  • Run gdrive to go through the authentication process with Google Drive.
  • Create a folder on Google Drive for your colorized output files.
  • Set your shell variable TALKODE_GDRIVE_OPTIONS="-p YOUR_GOOGLE_DRIVE_FOLDER_ID".

the colorize.sh script will automatically upload the colorized RTF file to Google Drive.

Once the file is uploaded into the folder, right-click to open it in Google Docs, and it will convert the RTF to the Google Docs format. See more details below under "Google Slides".

Simple highlighting

Keynote

The easiest way to get syntax-highlighted code in keynote slides, in my opinion, is copy the code so it's in your paste buffer, then pipe it through pygmentize into your copy buffer and then just paste it into keynote.

That essentially looks like this:

pbpaste | pygmentize -l ruby -f rtf -P style=presentation -P fontface="Source Code Pro" | pbcopy

The -P style=presentation bit says use the color highlighting scheme called presentation, which refers to the python file in this project.

Google Slides

Google Slides makes this a bit harder. Copy and pasting just doesn't work reliably. You have to use colorize.sh to create an RTF document, import the RTF document into Google Drive, then copy and paste from that document into slides or other documents.

Other applications

Sometimes you want to walk through an entire git history and colorize each step, or batch colorize a bunch of files.

Take a look at extract.sh and colorize.sh for a very hacky approach to doing that.

extract.sh

This is an extremely hacky script that colorizes ruby code for a range of git revisions.

It uses pygments (python library), and outputs .rtf.

The filename of the output is:

<unix timestamp of commit>_<commit hash>_<sanitized commit subject>_<old filename>.rtf

Usage

/path/to/extract.sh abcdef..HEAD~3 presentation /tmp/code_output

Pygments

I installed pygments for the Python interpreter like this:

sudo easy_install Pygments

If you are using Python via Homebrew, then the command is

easy_install Pygments

There are other ways of installing Pygments, so see Jekyll's Wiki (just scroll down to the part about python and pygments).

Keynote colors

I made a color palette for keynote that matches the presentation.py color scheme, and also has some colors for slides that represent terminal output.

~/Library/Colors/Programming.clr

These colors are in fact not just for Keynote. They are available in all your OS X applications that allow you to access the color palette provided by the system. Choose the color list tab in the colors dialog and click on the settings to open up the file in ~/Library/Colors.