Main Contents

puppet syntax highlighting with geshi

October 14, 2011

It’s no secret that I use Wordpress for this blog. One of the reasons I like Wordpress is the wide variety of plugins that are available. Since I blog a lot about perl/php/puppet code, I like to have a plugin that does syntax highlighting. For this task, I use the WP-Syntax plugin which is build on top of GeSHi.

Unfortunately, it doesn’t have a language file for puppet. A quick search turned up this language file. I installed it and noticed that it wasn’t picking up a lot of the keywords as resource types or attributes, nor was it recognizing C style multi-line comments (you know the ones that start with /* and end with */).

I was able to fix the comment issue right away. Then, I focused my attention towards automatically pulling the keywords either directly from the puppet source or from the puppet docs in some way programatically. I decided to grab them from the docs since I’m still a couple of versions behind (I’m running 2.6.9 and the latest stable version as of this writing is 2.7.5). I wrote a little perl script to spit out some pre-formatted text that I could just drop in as a replacement for the existing keywords arrays. Since I’ve been messing around with the puppetlabs-firewall module lately, I went ahead and added that resource type and attribute names manually. The script I used to pull and parse the data can be found on GitHub.

To use my language file, grab a copy of puppet.php from GitHub, then put it into your wp-content/plugins/wp-syntax/geshi/geshi folder. Then, use it like you would any other language WP-Syntax supports:

<pre lang="puppet">
exec { "some_exec":
    command => '/bin/echo "hello world" > /tmp/hello_world.txt'

And hopefully you’ll end up with something like this:

exec { "some_exec":
    command => '/bin/echo "hello world" > /tmp/hello_world.txt'

It’s not perfect, but I hope to continue to improve it over time. Enjoy!

Filed under: Puppet | Comments (1)

1 Comment

  1. Jason Antman’s Blog » Puppet Syntax Highlighting with GeSHi January 11, 2012 @ 10:32

    [...] Well, fellow Linux sysadmin and puppetmaster Jason Hancock was nice enough to post on his blog (Puppet Syntax Highlighting with GeSHi) that he’s developed a GeSHi language file for Puppet, available from GitHub. Many thanks! [...]

Leave a comment