[ Home | Feed | Twitter | Vector Art | Ascii Art | Tutorials ]

AsciiDoc with PyBlosxom

Thu, 16 Apr 2009

There are several tools that convert short text documents with wiki-like markup to HTML, PDF and other document formats. One such tool called AsciiDoc has been my favourite for a long time. PyBlosxom has plugins for light-weight markup languages like reStructured Text and Textile, but not for AsciiDoc. Now that I have chosen PyBlosxom as my blogging tool, I thought it might be a nice to add AsciiDoc support to PyBlosxom.

It turned out that writing a plugin for AsciiDoc is not that hard after all, thanks to the asciidocapi introduced in AsciiDoc 8.4.1. Here is a minimal AsciiDoc plugin.

AsciiDoc Plugin for PyBlosxom
from asciidocapi import AsciiDocAPI, AsciiDocError
import StringIO

def cb_preformat(args): 1
    if args['parser'] == 'asciidoc':
        return parse(''.join(args['story']))

def parse(text):
    infile = StringIO.StringIO(text)
    outfile = StringIO.StringIO()

        asciidoc = AsciiDocAPI("/home/bravegnu/asciidoc/asciidoc.py") 2
        asciidoc.execute(infile, outfile, backend='xhtml11')
    except AsciiDocError, e:
        return "<b>Asciidoc Error: %s</b>" % e

    return outfile.getvalue()
  1. Callback function that implements preformatting.

  2. Asciidoc API to invoke asciidoc from within python. The location of asciidoc module can be passed as an argument, or asciidocapi will try to infer it.

Permalink | Add Comment | Share: Twitter, Facebook, Buzz, ... | Tags: blosxom, python

blog comments powered by Disqus

Powered by Python | Made with PyBlosxom | Valid XHTML 1.1 | Best Viewed With Any Browser | Icon Credits | CC-BY-SA