-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path_split_into_md_files.py
69 lines (52 loc) · 1.94 KB
/
_split_into_md_files.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
60
61
62
63
64
65
66
67
68
69
import os
def make_file(name, text):
name = "documentation/" + name
name = name.replace("?", "")
path = "/".join(name.split("/")[:-1])
if not os.path.exists(path):
os.makedirs(path)
with open(name + ".md", "w", encoding="utf-8") as file:
file.write(text)
def format_name(text):
text = text.split("\n")[0]
text = text.replace(" ", "_")
text = text.replace(".", "_")
text = text.replace("__", "_")
return text
def create_big_tree():
"""
Useful for big docs
Make sidebar with almost all titles (#, ## and ###)
"""
with open("temp.md", encoding="utf-8") as f:
file = "".join(f.readlines())
chapters = file.split("\n# ")
for chapter in chapters:
chapter_name = format_name(chapter)
sections = chapter.split("\n## ")
for section in sections:
section_name = format_name(section)
subsections = section.split("\n### ")
for subsection in subsections:
subsection_name = format_name(subsection)
if len(subsections) > 1:
make_file(chapter_name + "/" + section_name + "/" + subsection_name, "# " + subsection)
elif len(sections) > 1:
make_file(chapter_name + "/" + section_name, "# " + subsection)
elif len(chapters) > 1:
make_file(chapter_name, "# " + subsection)
def create_small_tree():
"""
Useful for small plugins docs
Make sidebar with only main titles (#)
"""
with open("temp.md", encoding="utf-8") as f:
file = "".join(f.readlines())
chapters = file.split("\n# ")
i = 0
for chapter in chapters:
chapter_name = format_name(chapter)
if len(chapters) > 1:
make_file(str(i) + "_" + chapter_name, "# " + chapter)
i += 1
create_small_tree()