mirror of
https://github.com/lilydjwg/nvchecker.git
synced 2025-03-10 06:14:02 +00:00
add scripts/gen_contents
This commit is contained in:
parent
b6df5d6f2d
commit
a977a508d2
1 changed files with 40 additions and 0 deletions
40
scripts/gen_contents
Executable file
40
scripts/gen_contents
Executable file
|
@ -0,0 +1,40 @@
|
||||||
|
#!/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)
|
Loading…
Add table
Reference in a new issue