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
Very nice! Thank you!