Skip to content

Instantly share code, notes, and snippets.

@OddBloke
Created November 3, 2011 20:34
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save OddBloke/1337709 to your computer and use it in GitHub Desktop.
Save OddBloke/1337709 to your computer and use it in GitHub Desktop.
PyBlosxom reST Preview
from pprint import pformat
import sys
from docutils.core import publish_parts
content = []
meta = {}
def _handle_line(line):
if not line.startswith('#'):
content.append(line)
else:
key, value = line.strip('#\n').split(' ', 1)
meta[key] = value
for line in open(sys.argv[1]):
_handle_line(line)
sys.stderr.write(pformat(meta))
sys.stderr.write('\n')
title = content[0]
title_underline = "-" * len(title)
content.insert(1, title_underline + '\n')
print publish_parts(''.join(content), writer_name='html')['html_body']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment