I’m making some changes to this blog. I’ve been unhappy about the fact that all the code is static, not the code I use every day. Instead, I want a nice code repository, so whatever I write on my machine can be published directly, and if I update it, the updates end up here. I would also like syntactical highlighting of the code. And now, ta dah! It’s all done. Here’s what I did, for your reference and my own, because I’ll forget next time I need to update it.
So from now on, new code on this blog will look like this:
void setup() {
Serial.begin(9600);
}
void loop() {
Serial.println("Hello from Tom!");
}
And it’ll all be updated whenever I make changes. Exciting, isn’t it?
First, I set up a webDAV directory that’s linked to my code directory on my laptop. I looked at git, I thought about using subversion, but at the end of the day, I’m the only one who’ll be changing my code, so plain ol’ webDAV should work fine. It allows me to post files that can be viewed directly in a browser, or included by this blog all pretty-like. And unlike git, I don’t have to wrestle with the command line tools to make it happen (it’d be nice to see git integration with more of the GUI programming tools though). I use a few different coding tools, including Coda, Arduino, and Processing. Not all of them incorporate versioning tools, so that also makes webDAV appealing.
The WordPress plugin WP include-file does a nice job of pulling in remote files. It doesn’t do anything to make sure the included code is HTML-safe, though, so I made a slight change to it. Line 88 looks like this now:
$content = htmlentities(ob_get_clean());
The htmlentities() call cleans up things like the pointy brackets on some code includes, for example. Handy.
For code coloring, I use Syntax Highlighter MT, which is a wrapper around the javascript Syntax Highlighter. It has syntax coloring for a lot of languages, but not for Arduino or Processing. Fortunately, Sebastian Korczak wrote an extension brush for Syntax Highlighter for Processing. Since Processing and Arduino are similar, I modified Alex’ code to make a version for Arduino.
I had to make a couple modifications to Syntax Highlighter-MT. In the file stxhighlightmt.php, I added the following after line 154:
'mtsh_use_processing' => array(__('Processing'), 'Processing, processing', 'Processing'),
'mtsh_use_arduino' => array(__('Arduino'), 'Arduino, arduino', 'Arduino'));
I still need to modify WP-include-file so it takes a range of line numbers, so if anyone’s done that, or can do it, let me know.
That’s it, really. Hope it helps. I expect it’ll help me, at least.