Skip to content

Commit 729a11b

Browse files
authored
Added colon alignment
1 parent 3367981 commit 729a11b

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

align_yaml.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import re
22

3-
def align_yaml(str, pad=0):
3+
def align_yaml(str, pad=0, aligned_colons=False):
44
props = re.findall(r'^\s*[\S]+:', str, re.MULTILINE)
55
longest = max([len(i) for i in props]) + pad
66
return ''.join([i+'\n' for i in map(lambda str:
7-
re.sub(r'^(\s*.+?[^:#]: )\s*(.*)', lambda m:
8-
m.group(1) + ''.ljust(longest-len(m.group(1))+1) + m.group(2),
7+
re.sub(r'^(\s*.+?[^:#]): \s*(.*)' if aligned_colons else r'^(\s*.+?[^:#]: )\s*(.*)', lambda m:
8+
m.group(1) + ''.ljust(longest-len(m.group(1))+(-1-pad if aligned_colons else 1)) + (':'.ljust(pad+1) if aligned_colons else '') + m.group(2),
99
str, re.MULTILINE)
1010
, str.split('\n'))])

0 commit comments

Comments
 (0)