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()
try:
asciidoc = AsciiDocAPI("/home/bravegnu/asciidoc/asciidoc.py") 2
asciidoc.options('--no-header-footer')
asciidoc.execute(infile, outfile, backend='xhtml11')
except AsciiDocError, e:
return "<b>Asciidoc Error: %s</b>" % e
return outfile.getvalue()
-
Callback function that implements preformatting.
-
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