Added JS text renderer
authorThierry Florac <thierry.florac@onf.fr>
Mon, 17 Sep 2018 17:38:43 +0200
changeset 228 1edcd4c94110
parent 227 52a03aa1cf9d
child 229 c28aa20c304a
Added JS text renderer
src/pyams_utils/text.py
--- a/src/pyams_utils/text.py	Mon Sep 17 16:14:22 2018 +0200
+++ b/src/pyams_utils/text.py	Mon Sep 17 17:38:43 2018 +0200
@@ -81,6 +81,17 @@
         return html.escape(self.context).replace('\n', '<br />\n')
 
 
+@adapter_config(name='js', context=(str, IRequest), provides=IHTMLRenderer)
+class JsRenderer(BaseHTMLRenderer):
+    """Custom Javascript HTML renderer
+
+    This renderer replaces single quotes with escaped ones
+    """
+
+    def render(self, **kwargs):
+        return self.context.replace("'", "\\'")
+
+
 @adapter_config(name='rest', context=(str, IRequest), provides=IHTMLRenderer)
 class ReStructuredTextRenderer(BaseHTMLRenderer):
     """reStructuredText HTML renderer