[PATCH 2 of 2] templaterfilters: add 'newline' filter

Sean Farley sean.michael.farley at gmail.com
Wed Jan 9 12:12:40 CST 2013


# HG changeset patch
# User Sean Farley <sean.michael.farley at gmail.com>
# Date 1357671975 21600
# Node ID f8098885faa0fa09c8a9cfc887d807fa3c140cf4
# Parent  e9a1700097f2e520b5b0773f902cb92fe7af99ae
templaterfilters: add 'newline' filter

diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -130,10 +130,16 @@
 
 def fill76(text):
     """:fill76: Any text. Wraps the text to fit in 76 columns."""
     return fill(text, 76)
 
+def newline(text):
+    """:newline: Any text. If text is not empty, append \r\n."""
+    if text:
+        text += '\r\n'
+    return text
+
 def firstline(text):
     """:firstline: Any text. Returns the first line of text."""
     try:
         return text.splitlines(True)[0].rstrip('\r\n')
     except IndexError:
@@ -374,10 +380,11 @@
     "isodate": isodate,
     "isodatesec": isodatesec,
     "json": json,
     "jsonescape": jsonescape,
     "localdate": localdate,
+    "newline": newline,
     "nonempty": nonempty,
     "notfirstline": notfirstline,
     "obfuscate": obfuscate,
     "permissions": permissions,
     "person": person,


More information about the Mercurial-devel mailing list