Skip to content

Commit 42a8750

Browse files
authored
Create align.py
1 parent ee4f800 commit 42a8750

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

align.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import re
2+
3+
def align(str, pad=0):
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),
9+
str, re.MULTILINE)
10+
, str.split('\n'))])

0 commit comments

Comments
 (0)