-
Notifications
You must be signed in to change notification settings - Fork 52
/
Copy pathstyle.py
75 lines (49 loc) · 1.21 KB
/
style.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
70
71
72
73
74
75
from typing import List
def concatenate(text: List):
return "".join(filter(lambda x: x is not None, text))
def li(fp, text):
if isinstance(text, list):
text = concatenate(text)
fp.write("- " + text + "\n")
def lili(fp, text):
"""Second level of list items"""
fp.write("\t")
li(fp, text)
def h1(text):
return "# " + text + "\n"
def h2(text):
return "## " + text + "\n"
def h3(text):
return "### " + text + "\n"
def h4(text):
return "#### " + text + "\n"
def h5(text):
return "##### " + text + "\n"
def h6(text):
return "###### " + text + "\n"
def p(text):
if text is None:
return "\n"
else:
return str(text) + "\n"
def a(args: List):
if not isinstance(args, list):
args = [args]
if len(args) == 1:
src = args[0]
if src is None:
return ""
else:
return f"[{src}]({src})"
if len(args) == 2:
name = args[0]
src = args[1]
if name is None or src is None:
return ""
else:
return f"[{name}]({src})"
else:
raise NotImplementedError
def newline(fp, iter=1):
for _ in range(iter):
fp.write("\n")