Syntax Highlighting and Formulas for Blohg

I'm thus far thrilled with blohg as a blogging platform. I've got a large post I'm finishing up now with quite a few snippets of source code in two different programming languages. I was hoping to use the excellent SyntaxHighlighter javascript library to prettify those snippets, and was surprised to find that docutils reStructuredText doesn't yet do that (though some other implementations do).

Fortunately, adding new rendering directives to reStructuredText is incredibly easy. I was able to add support for a .. code mode with just this little bit of Python:

class Code(Directive):

    required_arguments = 1
    optional_arguments = 0
    has_content = True

    def run(self):
        self.options['brush'] = self.arguments[0]
        html = '''\

<pre class="brush: %s">
%s
</pre>
'''
        return [nodes.raw('', html % (self.options['brush'],
            "\n".join(self.content).replace('<', '<')),
            format='html')]

In a non-javascript environment (like your RSS reader) that should look like a standard <pre> tag, but at ry4an.org it should be colorful and tricked out.

I also wanted a good way to render mathematical formula's and saw that Rafael Martins had already included one in blohg. It, however, used a private (defunct?) mimetex server. Recalling Google provides a formula API I was able to cut over to that, allowing for turning things like this:

.. math::

   x = \frac{-b \pm \sqrt {b^2-4ac}}{2a}

into this:

https://chart.googleapis.com/chart?cht=tx&chl=x%20%3D%20%5Cfrac%7B-b%20%5Cpm%20%5Csqrt%20%7Bb%5E2-4ac%7D%7D%7B2a%7D

Neither of those are at all earth shattering, but maybe I'll be able to get Rafael to pull them anyway. Meanwhile they should merge cleanly into the blohg.