Add textToHTML function, using text renderers
authorThierry Florac <tflorac@ulthar.net>
Tue, 16 Mar 2010 01:29:07 +0100
changeset 40 16c94c509933
parent 39 cfcde480cdef
child 41 da1558b96f0a
Add textToHTML function, using text renderers
ztfy/utils/text.py
--- a/ztfy/utils/text.py	Fri Mar 05 00:20:28 2010 +0100
+++ b/ztfy/utils/text.py	Tue Mar 16 01:29:07 2010 +0100
@@ -22,8 +22,11 @@
 # import local interfaces
 
 # import Zope3 packages
+from zope.app import zapi
+from zope.component import createObject
 
 # import local packages
+from request import getRequest
 
 
 def textStart(text, length, max=0):
@@ -45,3 +48,11 @@
     if (index > 0) and (text_length > index + max):
         return result[:index] + '&#133;'
     return text
+
+
+def textToHTML(text, renderer='zope.source.plaintext', request=None):
+    if request is None:
+        request = getRequest()
+    formatter = createObject(renderer, text)
+    renderer = zapi.queryMultiAdapter((formatter, request), name=u'')
+    return renderer.render()