src/pyams_utils/text.py
changeset 228 1edcd4c94110
parent 226 830d5222e806
child 232 5dad602b4ca9
--- 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