We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 3367981 commit 729a11bCopy full SHA for 729a11b
align_yaml.py
@@ -1,10 +1,10 @@
1
import re
2
3
-def align_yaml(str, pad=0):
+def align_yaml(str, pad=0, aligned_colons=False):
4
props = re.findall(r'^\s*[\S]+:', str, re.MULTILINE)
5
longest = max([len(i) for i in props]) + pad
6
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),
+ re.sub(r'^(\s*.+?[^:#]): \s*(.*)' if aligned_colons else r'^(\s*.+?[^:#]: )\s*(.*)', lambda m:
+ 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),
9
str, re.MULTILINE)
10
, str.split('\n'))])
0 commit comments