Skip to content

Commit

Permalink
[doc] missing update readme script
Browse files Browse the repository at this point in the history
  • Loading branch information
krzysztof-jusiak committed Feb 25, 2016
1 parent 1c01c32 commit 63c6e29
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions doc/scripts/update_readme_toc.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#!/usr/bin/env python
#update_readme_toc.py doc/mkdocs.yml README.md http://boost-experimental.github.io/msm-lite

import fileinput, sys, os

generating = False
for line in fileinput.input(sys.argv[2], inplace=True):
if line.startswith('[](GENERATE_TOC_BEGIN)'):
generating = True
print(line)
with open(sys.argv[1], 'r') as file:
for line in file:
index = line.split(':')
if index[0][0] == '-':
ext = ('.html' if index[1][1:-4] == 'index' else '/index.html')
print('* [' + index[0][2:] + '](' + sys.argv[3] +'/' + index[1][1:-4] + ext + ')')
path = os.path.dirname(sys.argv[1])
with open((path + '/' if path != '' else '') + index[1][1:-1], 'r') as md:
for line in md:
if line.startswith('##'):
name = line.replace('#', '')[:-1]
id = filter(lambda c: c == '-' or c == '_' or str.isalnum(c), name.lower().replace(" ", "-")).replace("--", "")
print(' * [' + name + '](' + sys.argv[3] + '/' + index[1][1:-4] + ext + "#" + id + ')')
print
elif line.startswith('[](GENERATE_TOC_END)'):
generating = False
sys.stdout.write(line)
elif generating == False:
sys.stdout.write(line)

0 comments on commit 63c6e29

Please sign in to comment.