mercurial/templatefilters.py
changeset 6174 434139080ed4
parent 6134 7b937b26adf7
child 6229 c3182eeb70ea
--- a/mercurial/templatefilters.py	Sun Feb 24 17:58:55 2008 +0100
+++ b/mercurial/templatefilters.py	Mon Jan 28 22:19:12 2008 -0500
@@ -121,6 +121,15 @@
         return "-rwxr-xr-x"
     return "-rw-r--r--"
 
+def xmlescape(text):
+    text = (text
+            .replace('&', '&')
+            .replace('<', '&lt;')
+            .replace('>', '&gt;')
+            .replace('"', '&quot;')
+            .replace("'", '&#39;')) # &apos; invalid in HTML
+    return re.sub('[\x00-\x08\x0B\x0C\x0E-\x1F]', ' ', text)
+
 filters = {
     "addbreaks": nl2br,
     "basename": os.path.basename,
@@ -147,5 +156,6 @@
     "urlescape": lambda x: urllib.quote(x),
     "user": lambda x: util.shortuser(x),
     "stringescape": lambda x: x.encode('string_escape'),
+    "xmlescape": xmlescape,
     }