Added start and end tags to 'br' TALES extension
authorThierry Florac <thierry.florac@onf.fr>
Fri, 21 Sep 2018 10:21:52 +0200
changeset 232 5dad602b4ca9
parent 231 c7be97d76da1
child 233 3ba5d4160566
Added start and end tags to 'br' TALES extension
src/pyams_utils/text.py
--- a/src/pyams_utils/text.py	Wed Sep 19 08:42:16 2018 +0200
+++ b/src/pyams_utils/text.py	Fri Sep 21 10:21:52 2018 +0200
@@ -19,7 +19,7 @@
 import docutils.core
 from pyramid.interfaces import IRequest
 from zope.interface import Interface
-from zope.schema.vocabulary import SimpleVocabulary, SimpleTerm
+from zope.schema.vocabulary import SimpleTerm, SimpleVocabulary
 
 # import packages
 from pyams_utils.adapter import ContextRequestAdapter, ContextRequestViewAdapter, adapter_config
@@ -174,8 +174,16 @@
     """
 
     @staticmethod
-    def render(value, css_class='', character='|'):
+    def render(value, css_class='', character='|', start_tag=None, end_tag=None):
         if not value:
             return ''
         br = '<br {0} />'.format('class="{0}"'.format(css_class) if css_class else '')
-        return value.replace(character, br)
+        if start_tag or end_tag:
+            elements = value.split(character)
+            if start_tag:
+                elements[0] = '<{0}>{1}</{0}>'.format(start_tag, elements[0])
+            if end_tag:
+                elements[-1] = '<{0}>{1}</{0}>'.format(end_tag, elements[-1])
+            return br.join(elements)
+        else:
+            return value.replace(character, br)