159744507d556f518c6469d40824a31230e0c213
[pyblosxom-markdown2] / markdown-plugin.py
1 #!/usr/bin/env python
2 """
3 markdown-plugin.py -- A Python Markdown v2.x plugin for PyBlosxom.
4
5 This plugin requires Python Markdown v2.x, which you can download from:
6
7         http://www.freewisdom.org/projects/python-markdown/
8
9 Extract the 'markdown' directory from the Python Markdown tarball (the
10 directory containing __init__.py, not the Markdown-2.x.y directory)  into your
11 pyblosxom plugins dir alongside this plugin. Your plugins dir should look like
12 this:
13
14         plugins/ <-- your pyblosxom plugins dir
15                 markdown-plugin.py <-- this file
16                 markdown/ <-- the Python Markdown module
17                 ... <-- (any other pyblosxom plugins)
18
19 Now any posts with filenames ending in one of the FILENAME_EXTENSIONS defined
20 below will be passed through python-markdown.
21
22 Copyright (C) Benjamin Mako Hill, 2005
23 Rewritten by seanh 2009, 2010
24
25 """
26 _version__ = '0.3'
27 __author__ = 'Benjamin Mako Hill <mako@atdot.cc>'
28 __author__ = 'seanh <snhmnd@gmail.com>'
29
30 FILENAME_EXTENSIONS = ('.mdwn', '.txt','.text','.mkdn','.markdown','.md','.mdown','.markdn','.mkd')
31
32 import markdown
33 import os
34
35 md = markdown.Markdown(output_format='html4',extensions=['extra',])
36
37 def cb_story(args):
38         entry = args['entry']
39         if os.path.splitext(entry['filename'])[1] in FILENAME_EXTENSIONS:
40                 entry['body'] = md.convert(u''.join(entry['body'].decode("utf-8")))
41                 md.reset()
42         return args

Benjamin Mako Hill || Want to submit a patch?