Add textToHTML function, using text renderers
authorThierry Florac <tflorac@ulthar.net>
Tue, 16 Mar 2010 01:29:17 +0100
changeset 41 da1558b96f0a
parent 40 16c94c509933
child 42 cb2a0e2d3bbf
Add textToHTML function, using text renderers
ztfy/utils/tal/html.py
--- a/ztfy/utils/tal/html.py	Tue Mar 16 01:29:07 2010 +0100
+++ b/ztfy/utils/tal/html.py	Tue Mar 16 01:29:17 2010 +0100
@@ -24,15 +24,11 @@
 from interfaces import IHTMLTalesAPI
 
 # import Zope3 packages
-from zope.app import zapi
-from zope.app.renderer.plaintext import PlainTextToHTMLRenderer
-from zope.app.renderer.rest import ReStructuredTextToHTMLRenderer
-from zope.app.renderer.stx import StructuredTextToHTMLRenderer
-from zope.component import createObject
 from zope.interface import implements
 
 # import local packages
 from ztfy.utils.html import htmlToText
+from ztfy.utils.text import textToHTML
 
 
 class HTMLTalesAdapter(object):
@@ -53,20 +49,14 @@
     def text(self):
         if not self.context:
             return u''
-        formatter = createObject('zope.source.plaintext', self.context)
-        renderer = PlainTextToHTMLRenderer(formatter, self.request)
-        return renderer.render()
+        return textToHTML(self.context, 'zope.source.plaintext')
 
     def stx(self):
         if not self.context:
             return u''
-        formatter = createObject('zope.source.stx', self.context)
-        renderer = StructuredTextToHTMLRenderer(formatter, self.request)
-        return renderer.render()
+        return textToHTML(self.context, 'zope.source.stx')
 
     def rest(self):
         if not self.context:
             return u''
-        formatter = createObject('zope.source.rest', self.context)
-        renderer = ReStructuredTextToHTMLRenderer(formatter, self.request)
-        return renderer.render()
+        return textToHTML(self.context, 'zope.source.rest')