ATLAS Offline Software
Loading...
Searching...
No Matches
makeTOC.py
Go to the documentation of this file.
1# Copyright (C) 2002-2022 CERN for the benefit of the ATLAS collaboration
2
3import os,sys
4
5inFile="README.md"
6if len(sys.argv) >1:
7 inFile=sys.argv[1]
8
9f = open(inFile)
10
11regularLines=[]
12tocLines=[]
13
14afterBreak=False
15afterTOC=False
16inCodeBlock=False
17
18for line in f.readlines():
19 if '```' in line: inCodeBlock= not inCodeBlock
20 if '<br/>' in line:
21 afterBreak=True
22 if 'Table of Contents:' in line:
23 regularLines+=[line]
24 afterTOC=True
25 if not (afterTOC and not afterBreak): regularLines+=[line]
26
27 if '#'==line[0] and afterBreak and not inCodeBlock:
28 header=line.split('#')[-1].strip()
29 tag='#'+header.lower().replace(" ","-").replace(",","").replace("?","").replace("(","").replace(")","").replace("/","")
30 nIndents=line.count('#')
31 tocLine=""
32 for i in range(nIndents-1):
33 tocLine+="\t"
34 tocLine+="- [%s](%s)\n"%(header,tag)
35 tocLines+=[tocLine]
36
37fOut = open (inFile+".tmp",'w')
38
39for rl in regularLines:
40 fOut.write(rl)
41 if ('Table of Contents:') in rl:
42 for tl in tocLines:
43 fOut.write(tl)
44
45os.system('mv %s %s'%(inFile+".tmp",inFile))
std::string replace(std::string s, const std::string &s2, const std::string &s3)
Definition hcg.cxx:310