-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwrite_to_html.py
98 lines (82 loc) · 1.96 KB
/
write_to_html.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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
"""
Class used to write pytest warning data into html format
"""
import textwrap
import six
class HtmlOutlineWriter(object):
"""
writer to handle html writing
"""
HEAD = textwrap.dedent(
u"""
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
</head>
<style>
.toggle-box{
display:none;
}
.toggle-box + label + div {
display: none;
}
.toggle-box + label:before {
color: #888;
width: 10px;
}
.toggle-box:checked + label + div {
margin-left: 3%;
display: flex;
flex-direction: column;
}
div{
border-style: solid;
border-width: 1px 0px 0px 0px;
border-radius: 3px;
}
.location {
background-color: #edcca9
}
body {
background-color: cornsilk
}
.warning_text {
background-color: #d5b593
}
.warning{
background-color: #bd9f7d
}
.num {
background-color: #a68968;
}
.lineno {
background-color: #a68968;
}
}
</style>
<body>
"""
)
SECTION_START = textwrap.dedent(
u"""\
<div class="{klass}">
<input class="toggle-box {klass}" id="sect_{id:05d}" type="checkbox">
<label for="sect_{id:05d}">{html}</label>
<div>
"""
)
SECTION_END = six.u("</div></div>")
def __init__(self, fout):
self.fout = fout
self.section_id = 0
self.fout.write(self.HEAD)
def start_section(self, html, klass=None):
self.fout.write(
self.SECTION_START.format(id=self.section_id, html=html, klass=klass or "",)
)
self.section_id += 1
def end_section(self):
self.fout.write(self.SECTION_END)
def write(self, html):
self.fout.write(html)