-
Notifications
You must be signed in to change notification settings - Fork 0
/
unist.py
70 lines (42 loc) · 1.75 KB
/
unist.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
### Node Creation Tools
def text(value, **opts):
return {"type": "text", "value": value, **opts}
def link(children, url, **opts):
return {"type": "link", "url": url, "children": children, **opts}
def table(children, **opts):
return {"type": "table", "children": children, **opts}
def table_cell(children, **opts):
return {"type": "tableCell", "children": children, **opts}
def table_row(cells, **opts):
return {"type": "tableRow", "children": cells, **opts}
def span(children, style, **opts):
return {"type": "span", "children": children, "style": style, **opts}
def definition_list(children, **opts):
return {"type": "definitionList", "children": children, **opts}
def definition_term(children, **opts):
return {"type": "definitionTerm", "children": children, **opts}
def definition_description(children, **opts):
return {"type": "definitionDescription", "children": children, **opts}
def list_(children, ordered=False, spread=False, **opts):
return {
"type": "list",
"ordered": ordered,
"spread": spread,
"children": children,
**opts,
}
def list_item(children, spread=True, **opts):
return {"type": "listItem", "spread": spread, "children": children, **opts}
def image(url, **opts):
return {"type": "image", "url": url, **opts}
def grid(columns, children, **opts):
return {"type": "grid", "columns": columns, "children": children, **opts}
def div(children, **opts):
return {"type": "div", "children": children, **opts}
def find_all_by_type(parent: dict, type_: str):
for node in parent["children"]:
if node["type"] == type_:
yield node
if "children" not in node:
continue
yield from find_all_by_type(node, type_)