Handle various filename extensions that people use with markdown.
[pyblosxom-markdown2] / markdown-plugin.py
index f9140f7732d4d5e94decd7bce293d4538beac275..3224c6350b5366e20b10b7f328b38bf4c2fccf79 100644 (file)
@@ -6,7 +6,7 @@ This plugin requires Python-Markdown v2.x, which you can download from:
 
     http://www.freewisdom.org/projects/python-markdown/
 
-Extract python-markdown into your pyblosxom plugins dir alongside this 
+Extract python-markdown into your pyblosxom plugins dir alongside this
 plugin. Your plugins dir should look like this:
 
     plugins/ <-- your pyblosxom plugins dir
@@ -15,9 +15,9 @@ plugin. Your plugins dir should look like this:
         markdown/ <-- directory containing python-markdown's files
         ... <-- (any other pyblosxom plugins)
 
-Now any posts with filenames ending in `.mkdn` will be passed through 
+Now any posts with filenames ending in `.mkdn` will be passed through
 python-markdown.
-   
+
 Copyright (C) Benjamin Mako Hill, 2005
 Updated for python-markdown 2 by seanh 2009
 
@@ -38,7 +38,7 @@ USA.
 
 """
 PREFORMATTER_ID = 'markdown'
-FILE_EXT = 'mkdn'
+FILENAME_EXTENSIONS = ('txt','text','mkdn','markdown','md','mdown','markdn','mkd')
 _version__ = '0.2'
 __author__ = 'Benjamin Mako Hill <mako@atdot.cc>'
 __author__ = 'seanh'
@@ -58,31 +58,22 @@ md = markdown.Markdown(
                  #'meta',
                  #'rss',
                  'toc',
-                 #'wikilinks'               
+                 #'wikilinks'
                ]
 )
 
 def cb_entryparser(args):
-    args[FILE_EXT] = readfile
+    for FILENAME_EXTENSION in FILENAME_EXTENSIONS:
+        args[FILENAME_EXTENSION] = readfile
     return args
 
 def cb_preformat(args):
     if args['parser'] == PREFORMATTER_ID:
         return parse(''.join(args['story']))
 
-def to_ascii(char):
-    """Return char if char is an ASCII character, '?' otherwise."""
-    if ord(char) < 128:
-        return char
-    else:
-        return '?'
-
-def parse(story):    
-    # Replace any non-ascii characters in the story with '?', so that
-    # python-markdown doesn't crash.
-    ascii = "".join([to_ascii(x) for x in story])
+def parse(story):
     # Convert the ASCII text to HTML with python-markdown.
-    html = md.convert(ascii)
+    html = md.convert(story)
     # Reset python-markdown ready for next time.
     md.reset()
     return html

Benjamin Mako Hill || Want to submit a patch?