-
Notifications
You must be signed in to change notification settings - Fork 21
/
convert_html_help_to_rst.py
37 lines (30 loc) · 1.1 KB
/
convert_html_help_to_rst.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
import os
import argparse
import re
parser = argparse.ArgumentParser()
parser.add_argument("input",help="path to input html file")
args = parser.parse_args()
def convert_html(file_path):
cleanr = re.compile('<.*?>')
output = os.path.basename(file_path)
output = output.replace(".html","-tmp.txt")
output = output.replace(".htm","-tmp.txt")
with open(file_path,"rb") as opened:
lines = opened.readlines()
with open(output,"wb") as outfile:
for line in lines:
if "{% load i18n %}" in line:
continue
if not "src=" in line:
line = re.sub(cleanr, '', line)
line = line.replace('{% trans "',"")
line = line.replace('" %}',"")
line = line.replace('{% blocktrans %}',"")
line = line.replace('{% endblocktrans %}',"")
line = line.replace(" ","")
if line.rstrip() == "":
continue
outfile.write(line)
print(output)
if __name__ == "__main__":
convert_html(args.input)