blob: 553aff5561be7392ffbc7f15626f0f9de7d7db27 [file] [log] [blame]
koder aka kdanilova732a602017-02-01 20:29:56 +02001from typing import Optional, List, Callable
2
3
4import xmlbuilder3
5
6
7eol = "<br>"
8
9
10def tag(name: str) -> Callable[[str], str]:
11 def closure(data: str) -> str:
12 return "<{}>{}</{}>".format(name, data, name)
13 return closure
14
15
16H3 = tag("H3")
17H2 = tag("H2")
18center = tag("center")
19
20
21def img(link: str) -> str:
koder aka kdanilov108ac362017-01-19 20:17:16 +020022 return '<img src="{}">'.format(link)
koder aka kdanilova732a602017-02-01 20:29:56 +020023
24
25def table(caption: str, headers: Optional[List[str]], data: List[List[str]]) -> str:
26 doc = xmlbuilder3.XMLBuilder("table",
27 **{"class": "table table-bordered table-striped table-condensed table-hover",
28 "style": "width: auto;"})
29
30 doc.caption.H3.center(caption)
31
32 if headers is not None:
33 with doc.thead:
34 with doc.tr:
35 for header in headers:
36 doc.th(header)
37
38 with doc.tbody:
39 for line in data:
40 with doc.tr:
41 for vl in line:
42 doc.td(vl)
43
44 return xmlbuilder3.tostr(doc).split("\n", 1)[1]