3 markdown-plugin.py -- A Python-Markdown v2.x plugin for PyBlosxom.
5 This plugin requires Python-Markdown v2.x, which you can download from:
7 http://www.freewisdom.org/projects/python-markdown/
9 Extract python-markdown into your pyblosxom plugins dir alongside this
10 plugin. Your plugins dir should look like this:
12 plugins/ <-- your pyblosxom plugins dir
13 markdown-plugin.py <-- this file
14 markdown.py <-- the python-markdown command line script
15 markdown/ <-- directory containing python-markdown's files
16 ... <-- (any other pyblosxom plugins)
18 Now any posts with filenames ending in `.mkdn` will be passed through
21 Copyright (C) Benjamin Mako Hill, 2005
22 Updated for python-markdown 2 by seanh 2009
24 This program is free software; you can redistribute it and/or modify
25 it under the terms of the GNU General Public License as published by
26 the Free Software Foundation; either version 2 of the License, or (at
27 your option) any later versi
29 This program is distributed in the hope that it will be useful, but
30 WITHOUT ANY WARRANTY; without even the implied warranty of
31 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
32 General Public License for more details.
34 You should have received a copy of the GNU General Public License
35 along with this program; if not, write to the Free Software
36 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
40 PREFORMATTER_ID = 'markdown'
41 FILENAME_EXTENSIONS = ('txt','text','mkdn','markdown','md','mdown','markdn','mkd')
43 __author__ = 'Benjamin Mako Hill <mako@atdot.cc>'
48 from Pyblosxom import tools
50 md = markdown.Markdown(
52 output_format='html4',
53 extensions=[ 'codehilite', # Requires python-pygments
54 'extra', # Abbreviations, definition lists, fenced code blocks,
55 # footnotes, headerid and tables.
56 #'html_tidy', # Enable this if you have libtidy and uTidylib
57 #'imagelinks', # Broken?
65 def cb_entryparser(args):
66 for FILENAME_EXTENSION in FILENAME_EXTENSIONS:
67 args[FILENAME_EXTENSION] = readfile
70 def cb_preformat(args):
71 if args['parser'] == PREFORMATTER_ID:
72 return parse(''.join(args['story']))
75 # Convert the ASCII text to HTML with python-markdown.
76 html = md.convert(story)
77 # Reset python-markdown ready for next time.
81 def readfile(filename, request):
83 lines = codecs.open(filename, mode="r", encoding="utf8").readlines()
84 title = lines.pop(0).strip()
85 while lines and lines[0].startswith("#"):
87 meta = meta[1:].strip()
88 meta = meta.split(" ", 1)
89 entryData[meta[0].strip()] = meta[1].strip()
90 entryData['title'] = title
91 entryData['body'] = parse(''.join(lines))
92 # Call the postformat callbacks
93 tools.run_callback('postformat',
95 'entry_data': entryData})