-
Notifications
You must be signed in to change notification settings - Fork 0
/
createmkdoc.py
executable file
·59 lines (48 loc) · 1.44 KB
/
createmkdoc.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
from bs4 import BeautifulSoup
import json
import re
import yaml
f = open("src/product/tree.html", "r")
soup = BeautifulSoup(f)
elements = soup.find(name="div", attrs={ "content":"tree"})
jsontree = json.loads(elements.getText())
print(jsontree)
mainElement = jsontree[0]
elements = mainElement['children']
pagelist = []
def extractElements(element, baseroot=""):
if element is None:
return
if isinstance(element, list):
for i in element:
extractElements(i, baseroot)
else:
href = element['href']
text = ""
if "text" in element:
text = element['text']
if not href is None:
pattern = re.compile("mdwiki.html\\#\\!(.*)$")
m = pattern.match(href)
if m:
filename = m.group(1)
pagelist.append({ text: "src/product/" + filename })
if "children" in element:
children = element['children']
if children is not None:
extractElements(children)
extractElements(mainElement)
with open("mkdocs.yml","w") as output_file:
content = {
"site_name": "APrint Documentation",
"theme": {
"name": 'material' },
#"extra_css": [
# "css/extra.css"
#],
"plugins": [ "search",
{"pdf-export": {"combined": True}}],
"nav" : pagelist
}
output_file.write(yaml.dump(content))
print("Done")