Show More
@@ -299,7 +299,7 b' def isodatesec(text):' | |||
|
299 | 299 | return dateutil.datestr(text, b'%Y-%m-%d %H:%M:%S %1%2') |
|
300 | 300 | |
|
301 | 301 | |
|
302 | def indent(text, prefix): | |
|
302 | def indent(text, prefix, firstline=b''): | |
|
303 | 303 | '''indent each non-empty line of text after first with prefix.''' |
|
304 | 304 | lines = text.splitlines() |
|
305 | 305 | num_lines = len(lines) |
@@ -308,8 +308,8 b' def indent(text, prefix):' | |||
|
308 | 308 | def indenter(): |
|
309 | 309 | for i in pycompat.xrange(num_lines): |
|
310 | 310 | l = lines[i] |
|
311 |
if |
|
|
312 | yield prefix | |
|
311 | if l.strip(): | |
|
312 | yield prefix if i else firstline | |
|
313 | 313 | yield l |
|
314 | 314 | if i < num_lines - 1 or endswithnewline: |
|
315 | 315 | yield b'\n' |
@@ -310,13 +310,11 b' def indent(context, mapping, args):' | |||
|
310 | 310 | text = evalstring(context, mapping, args[0]) |
|
311 | 311 | indent = evalstring(context, mapping, args[1]) |
|
312 | 312 | |
|
313 | firstline = indent | |
|
313 | 314 | if len(args) == 3: |
|
314 | 315 | firstline = evalstring(context, mapping, args[2]) |
|
315 | else: | |
|
316 | firstline = indent | |
|
317 | 316 | |
|
318 | # the indent function doesn't indent the first line, so we do it here | |
|
319 | return templatefilters.indent(firstline + text, indent) | |
|
317 | return templatefilters.indent(text, indent, firstline=firstline) | |
|
320 | 318 | |
|
321 | 319 | |
|
322 | 320 | @templatefunc(b'get(dict, key)') |
@@ -6,6 +6,9 b'' | |||
|
6 | 6 | |
|
7 | 7 | == Bug Fixes == |
|
8 | 8 | |
|
9 | * The `indent()` template function was documented to not indent empty lines, | |
|
10 | but it still indented the first line even if it was empty. It no longer does | |
|
11 | that. | |
|
9 | 12 | |
|
10 | 13 | == Backwards Compatibility Changes == |
|
11 | 14 |
@@ -1507,16 +1507,16 b' Test indent and not adding to empty line' | |||
|
1507 | 1507 | Test indent with empty first line |
|
1508 | 1508 | |
|
1509 | 1509 | $ hg version -T "{indent('', '>> ')}\n" |
|
1510 | >> | |
|
1510 | ||
|
1511 | 1511 | |
|
1512 | 1512 | $ hg version -T "{indent(' |
|
1513 | 1513 | > second', '>> ')}\n" |
|
1514 | >> | |
|
1514 | ||
|
1515 | 1515 | >> second |
|
1516 | 1516 | |
|
1517 | 1517 | $ hg version -T "{indent(' |
|
1518 | 1518 | > second', '>> ', ' > ')}\n" |
|
1519 | > | |
|
1519 | ||
|
1520 | 1520 | >> second |
|
1521 | 1521 | |
|
1522 | 1522 | Test with non-strings like dates |
General Comments 0
You need to be logged in to leave comments.
Login now