Back to index

plone3  3.1.7
text_pre_to_html.py
Go to the documentation of this file.
00001 from Products.PortalTransforms.interfaces import itransform
00002 from DocumentTemplate.DT_Util import html_quote
00003 
00004 __revision__ = '$Id: text_pre_to_html.py 3658 2005-02-23 16:29:54Z tiran $'
00005 
00006 class TextPreToHTML:
00007     """simple transform which wraps raw text into a <pre> tag"""
00008 
00009     __implements__ = itransform
00010 
00011     __name__ = "text-pre_to_html"
00012     inputs   = ('text/plain-pre',)
00013     output = "text/html"
00014 
00015     def __init__(self, name=None):
00016         self.config_metadata = {
00017             'inputs' : ('list', 'Inputs', 'Input(s) MIME type. Change with care.'),
00018             }
00019         if name:
00020             self.__name__ = name
00021 
00022     def name(self):
00023         return self.__name__
00024 
00025     def __getattr__(self, attr):
00026         if attr == 'inputs':
00027             return self.config['inputs']
00028         if attr == 'output':
00029             return self.config['output']
00030         raise AttributeError(attr)
00031 
00032     def convert(self, orig, data, **kwargs):
00033         data.setData('<pre class="data">%s</pre>' % html_quote(orig))
00034         return data
00035 
00036 def register():
00037     return TextPreToHTML()