41 lines
678 B
Python
Executable File
41 lines
678 B
Python
Executable File
#!/usr/bin/env python3
|
|
|
|
import sys
|
|
import re
|
|
|
|
sections = re.compile(r'[-=]{3,}')
|
|
levels = {
|
|
'=': 1,
|
|
'-': 2,
|
|
}
|
|
|
|
def to_id(t):
|
|
return t.lower().replace(' ', '-').replace('`', '')
|
|
|
|
def to_text(t):
|
|
return t.replace('`', '')
|
|
|
|
def main(f):
|
|
L = []
|
|
last = None
|
|
for l in f:
|
|
l = l[:-1]
|
|
if sections.fullmatch(l):
|
|
L.append((last, levels[l[0]]))
|
|
last = l
|
|
|
|
last_lvl = 1
|
|
for title, lvl in L:
|
|
indent = ' ' * (lvl - 1)
|
|
if last_lvl != lvl:
|
|
print()
|
|
print('{indent}* `{text} <#{id}>`_'.format(
|
|
indent = indent,
|
|
text = to_text(title),
|
|
id = to_id(title),
|
|
))
|
|
last_lvl = lvl
|
|
|
|
if __name__ == '__main__':
|
|
main(sys.stdin)
|