3 markdown-plugin.py -- A python-markdown 2 plugin for pyblosxom.
5 This plugin requires python-markdown 2, which you can download from:
7 http://www.freewisdom.org/projects/python-markdown/
9 Extract python-markdown 2 into your pyblosxom plugins dir alongside this plugin.
10 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 python-markdown.
20 Copyright (C) Benjamin Mako Hill, 2005
21 Updated for python-markdown 2 by seanh 2009
23 This program is free software; you can redistribute it and/or modify
24 it under the terms of the GNU General Public License as published by
25 the Free Software Foundation; either version 2 of the License, or (at
26 your option) any later versi
28 This program is distributed in the hope that it will be useful, but
29 WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with this program; if not, write to the Free Software
35 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
39 PREFORMATTER_ID = 'markdown'
42 __author__ = 'Benjamin Mako Hill <mako@atdot.cc>'
47 from Pyblosxom import tools
49 md = markdown.Markdown(
51 output_format='html4',
52 extensions=[ 'codehilite', # Requires python-pygments
53 'extra', # Abbreviations, definition lists, fenced code blocks,
54 # footnotes, headerid and tables.
55 #'html_tidy', # Enable this if you have libtidy and uTidylib
56 #'imagelinks', # Broken?
64 def cb_entryparser(args):
65 args[FILE_EXT] = readfile
68 def cb_preformat(args):
69 if args['parser'] == PREFORMATTER_ID:
70 return parse(''.join(args['story']))
73 """Return char if char is an ASCII character, '?' otherwise."""
80 # Replace any non-ascii characters in the story with '?', so that
81 # python-markdown doesn't crash.
82 ascii = "".join([to_ascii(x) for x in story])
83 # Convert the ASCII text to HTML with python-markdown.
84 html = md.convert(ascii)
85 # Reset python-markdown ready for next time.
89 def readfile(filename, request):
91 lines = codecs.open(filename, mode="r", encoding="utf8").readlines()
92 title = lines.pop(0).strip()
93 while lines and lines[0].startswith("#"):
95 meta = meta[1:].strip()
96 meta = meta.split(" ", 1)
97 entryData[meta[0].strip()] = meta[1].strip()
98 entryData['title'] = title
99 entryData['body'] = parse(''.join(lines))
100 # Call the postformat callbacks
101 tools.run_callback('postformat',
103 'entry_data': entryData})