8a262b051b86cb586a0ead05b936a32a6f176256
[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 Updated for Python Markdown 2 by seanh 2009
24
25 This program is free software; you can redistribute it and/or modify
26 it under the terms of the GNU General Public License as published by
27 the Free Software Foundation; either version 2 of the License, or (at
28 your option) any later versi
29
30 This program is distributed in the hope that it will be useful, but
31 WITHOUT ANY WARRANTY; without even the implied warranty of
32 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
33 General Public License for more details.
34
35 You should have received a copy of the GNU General Public License
36 along with this program; if not, write to the Free Software
37 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
38 USA.
39
40 """
41 _version__ = '0.3'
42 __author__ = 'Benjamin Mako Hill <mako@atdot.cc>'
43 __author__ = 'seanh <snhmnd@gmail.com>'
44
45 FILENAME_EXTENSIONS = ('.txt','.text','.mkdn','.markdown','.md','.mdown','.markdn','.mkd')
46
47 import markdown
48 import os
49
50 md = markdown.Markdown(output_format='html4',extensions=['extra',])
51
52 def cb_story(args):
53         entry = args['entry']
54         if os.path.splitext(entry['filename'])[1] in FILENAME_EXTENSIONS:
55                 entry['body'] = md.convert(''.join(entry['body']))
56                 md.reset()
57         return args

Benjamin Mako Hill || Want to submit a patch?