-
Notifications
You must be signed in to change notification settings - Fork 12
/
makeman.py
executable file
·27 lines (25 loc) · 987 Bytes
/
makeman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#!/usr/bin/env python3
def get_readme_section(filename, start="BEGIN", end="END"):
with open(filename, 'r') as readme:
summary = []
lines = readme.readlines()
section = None
for line in lines:
if section is None and start in line:
section = line.split()[line.split().index(start) + 1]
summary.append('[={0}]\n'.format(section))
elif section:
if end in line:
section = None
else:
if line.startswith('##'):
line = line.strip('##')
line = '.B ' + line + '\n'
summary.append(line)
return ''.join(summary)
if __name__=='__main__':
summary = get_readme_section('README.md')
with open('manpage.in', 'w') as manpage:
name = '\n[=NAME]\n\nsmudge - smudge programming language\n'
manpage.write(name)
manpage.write(summary)