-
Notifications
You must be signed in to change notification settings - Fork 14
/
FixFileFormatHTML.py
59 lines (52 loc) · 1.85 KB
/
FixFileFormatHTML.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import os
import glob
################
# File formats #
################
for filename in glob.glob(os.path.join("_build", "html", "FileFormats", "*.html")):
with open(filename, encoding="utf-8") as inp:
text = inp.readlines()
with open(filename, "w", encoding="utf-8") as output:
for line in text:
if line.startswith("<kbd><span class=\"option\">-"):
output.write("<kbd><span class=\"option\">" + line[27:])
else:
output.write(line)
# Fix LaTeX
filename = os.path.join("_build", "latex", "OpenBabel.tex")
startfixing = False
if os.path.isfile(filename):
input = open(filename, "r")
text = input.readlines()
output = open(filename, "w")
for line in text:
if line.startswith("\chapter{Supported File Formats and Options}"):
startfixing = True
if startfixing and line.startswith("\item [-"):
output.write("\item [" + line[8:])
else:
output.write(line)
#################
# ---errorlevel #
#################
def fix(filename, before, after):
inputfile = filename
fixed = False
if os.path.isfile(inputfile):
with open(inputfile, encoding="utf-8") as inp:
text = inp.readlines()
with open(inputfile, "w", encoding="utf-8") as output:
for line in text:
if line.startswith(before):
output.write(after + line[len(before):])
fixed = True
else:
output.write(line)
return fixed
fix(os.path.join("_build", "html", "Command-line_tools", "babel.html"),
"<kbd><span class=\"option\">--errorlevel",
"<kbd><span class=\"option\">---errorlevel")
fix(os.path.join("_build", "latex", "OpenBabel.tex"),
"\item [-{-}errorlevel",
"\item [-{-}{-}errorlevel")
print("Fixed HTML and LaTeX")