Skip to content

Instantly share code, notes, and snippets.

@skmetz
Created June 21, 2016 05:38
Show Gist options
  • Save skmetz/7b502c0eaa8343524a81d2b9091a8f9b to your computer and use it in GitHub Desktop.
Save skmetz/7b502c0eaa8343524a81d2b9091a8f9b to your computer and use it in GitHub Desktop.
Script to create syntax highlighted RTF files
#!/bin/bash
# I edited the ruby lexer (line 637 in the following file...
# [skm@skmair2:/Library/Python/2.7/site-packages/pygments/lexers/agile.py
# to remove spacial handling of the word 'name'
# so I could use it as a variable/method name.
# This script come from Katrina, with these instructions:
# I've also attached the presentation.py file which is where the style
# is defined. The colors are normal hex values, so if you know how you
# want your code, you can tweak this yourself.
# I had to stick this in
# /Library/Python/2.7/site-packages/Pygments-1.6rc1-py2.7.egg/pygments/styles/
# for pygments to know where to find it, you might have different
# versions, of course.
for file in `ls -1 . | grep .rb`
do
outfile="colorized/`basename $file .rb`.rtf"
style="style=default"
font="fontface=Consolas"
lexer="ruby"
format="rtf"
fontsize="48" # twice the actual size, so 48 = 24
blanklinesize="24" # ditto
# sed command to insert overall fontsize into rtf file
sed1="sed s/\\\\f0/\\\\f0\\\\fs$fontsize/g"
# sed command to change the fontsize for a blank line.
# blank lines contain only ^\par$, so this changes
# \par (where $fontsize=48 and $blanklinesize=24) to
# \fo\fs24\par\f0\fs48
sed2="sed s/^\\\\par$/\\\\f0\\\\fs$blanklinesize\\\\par\\\\f0\\\\fs$fontsize/g"
pygmentize -l $lexer -P $style -P "$font" -f $format $file | $sed1 | $sed2 > $outfile
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment