Back to index

plone3  3.1.7
markdown_to_html.py
Go to the documentation of this file.
00001 """
00002 Uses the http://www.freewisdom.org/projects/python-markdown/ module to do its handy work
00003 
00004 author: Tom Lazar <tom@tomster.org> at the archipelago sprint 2006
00005 
00006 """
00007 
00008 from Products.PortalTransforms.interfaces import itransform
00009 from Products.PortalTransforms.libtransforms.utils import bin_search, sansext
00010 from Products.PortalTransforms.libtransforms.commandtransform import commandtransform
00011 from Products.CMFDefault.utils import bodyfinder
00012 import os
00013 
00014 try:
00015     import markdown as markdown_transformer
00016 except ImportError:
00017     HAS_MARKDOWN = False
00018 else:
00019     HAS_MARKDOWN = True
00020     
00021 
00022 class markdown:
00023     __implements__ = itransform
00024 
00025     __name__ = "markdown_to_html"
00026     inputs  = ("text/x-web-markdown",)
00027     output = "text/html"
00028 
00029     def name(self):
00030         return self.__name__
00031 
00032     def convert(self, orig, data, **kwargs):
00033         if HAS_MARKDOWN:
00034             html = markdown_transformer.markdown(orig)
00035         else:
00036             html = orig
00037         data.setData(html)
00038         return data
00039 
00040 def register():
00041     return markdown()