Mercurial > public > mercurial-scm > hg-stable
diff mercurial/templatefilters.py @ 43735:fa246ada356b
templates: make {indent("", " ")} be empty
indent() is documented to indent all non-empty lines, but it made an
exception for the first line, which always got indented. I also made
indent() not indent the first line even if an indent override was
given for the first line. I think that is what one would usually want.
Differential Revision: https://phab.mercurial-scm.org/D7432
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Fri, 15 Nov 2019 10:16:27 -0800 |
parents | 91c746a77fa3 |
children | e3e44e6e7245 |
line wrap: on
line diff
--- a/mercurial/templatefilters.py Fri Nov 15 10:16:22 2019 -0800 +++ b/mercurial/templatefilters.py Fri Nov 15 10:16:27 2019 -0800 @@ -299,7 +299,7 @@ return dateutil.datestr(text, b'%Y-%m-%d %H:%M:%S %1%2') -def indent(text, prefix): +def indent(text, prefix, firstline=b''): '''indent each non-empty line of text after first with prefix.''' lines = text.splitlines() num_lines = len(lines) @@ -308,8 +308,8 @@ def indenter(): for i in pycompat.xrange(num_lines): l = lines[i] - if i and l.strip(): - yield prefix + if l.strip(): + yield prefix if i else firstline yield l if i < num_lines - 1 or endswithnewline: yield b'\n'