[PATCH] Added template filter for converting white spaces to a newline

Doug Simon Doug.Simon at sun.com
Thu Oct 9 17:34:08 CDT 2008


# HG changeset patch
# User Doug Simon <doug.simon at sun.com>
# Date 1223590072 25200
# Node ID 51dcd360b16d8eca3f54e147f6ac5c96f2c2091c
# Parent  643c751e60b248e4672f53633e040929f8041dc0
Added template filter for converting white spaces to a newline.

This patch adds a 'ws2nl' template filter that converts one or more
adjacent white spaces characters to a single newline character. This
makes it possible to apply newline based filters to template keywords
that generate a list of strings. For example, to show each file modified
in a changeset, one line per file, the following can be used in a  
template:

     \t{files|stringify|ws2nl|tabindent}\n

diff -r 643c751e60b2 -r 51dcd360b16d mercurial/templatefilters.py
--- a/mercurial/templatefilters.py	Wed Oct 08 19:58:35 2008 -0500
+++ b/mercurial/templatefilters.py	Thu Oct 09 15:07:52 2008 -0700
@@ -175,6 +175,7 @@
     "short": lambda x: x[:12],
     "shortdate": util.shortdate,
     "stringify": templater.stringify,
+    "ws2nl": lambda x: re.sub('\s+', '\n', x),
     "strip": lambda x: x.strip(),
     "urlescape": lambda x: urllib.quote(x),
     "user": lambda x: util.shortuser(x),



More information about the Mercurial mailing list