Skip to content

Instantly share code, notes, and snippets.

@TJkrusinski
Created February 10, 2014 17:50
Show Gist options
  • Save TJkrusinski/8920761 to your computer and use it in GitHub Desktop.
Save TJkrusinski/8920761 to your computer and use it in GitHub Desktop.
Syntax highlighting in keynote made easy

Keynote I guess pushed an update that doesn't take hightlighted code from xCode anymore. So, I googled around and found hightlight. It is a super useful utitlity to do syntax highlighting from the command line.

$ brew install hightlight

If you are on Mavericks you may need to brew link lua to get it working right.

Hightlight has support for all kinds of languages and themes and it can wrap the code with line numbers, which is great.

I made an alias on my bash profile to take what is on my clipboard, pipe it into highlight, then pipe it back to my clipboard.

alias hit="pbpaste | highlight --syntax=js --style=zenburn --line-numbers -O rtf | pbcopy"

So if I want to highlight the code I have copied, I jump over to the terminal, run hit and then paste it into keynote. It's an extra step but it removes the need to use xcode. Since I don't need xcode anymore, I can cat files into pbcopy, then run hit and never leave the terminal.

You can use sed to get spcific lines of a file to stdout so I made another alias _hit that removes the first pipe of pbpaste

alias _hit="highlight --syntax=js --style=zenburn --line-numbers -O rtf | pbcopy"

So if I wanted to get lines 10-15 of a file highlighted, could do

sed -n 10,15p app.js | _hit
@jcabmora
Copy link

Very nice! Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment