code highlighting for keynote

经常需要在keynote中插入代码,大块的代码有语法高亮更易读一些。

配置和使用

Step 0:

Get Homebrew installed on your mac if you don't already have it

Step 1:

Install highlight. "brew install highlight". (This brings down Lua and Boost as well)

Step 2:

Highlight your source. "highlight -O rtf myfile.php | pbcopy". This will highlight the source code in RTF format and copy the result of that operation to your Mac's clipboard.

Step 3:

Paste into your slide in Keynote. Keynote will create a new text box with your highlighted code. You can adjust the width as needed, and adjust the font size with cmd+ and cmd-

More

固定配置形成一个脚本

每次敲命令太复杂,自己写一个脚本hlfile

#! /bin/bash

cat $1 | highlight --syntax=js --line-numbers --font-size 24 --font Inconsolata --style Seashell -O rtf | pbcopy

其中

  • --syntax 语法,我常用js
  • --style highlight的theme,参考Theme samples, 运行highlight -w可以查看安装的主题
  • --line-numbers 显示行号

更多选项可以运行highlight -h查看

高亮的具体效果可以看这篇文章 中的keynote

结合sed

结合sed,可以高亮指定行号区间的代码,vim中

:!sed -n '20,35p' % | hlfile

Reference

comments powered by Disqus