Skip to content

Commit 79a9cb1

Browse files
committed
🐛 [HTML] Fix table headers
1 parent 4b88fd7 commit 79a9cb1

File tree

15 files changed

+210
-156
lines changed

15 files changed

+210
-156
lines changed

src/backends/html/html_backend.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ function _html__print(
146146
push!(vproperties, "class" => table_div_class)
147147

148148
empty!(vstyle)
149-
push!(vproperties, "overflow-x" => "scroll")
149+
push!(vstyle, "overflow-x" => "scroll")
150150

151151
_aprintln(
152152
buf,
@@ -186,7 +186,7 @@ function _html__print(
186186

187187
if action == :new_row
188188

189-
if (ps.i == 1) && (rs (:table_header, :column_label)) && !head_opened
189+
if (ps.i == 1) && (rs (:table_header, :column_labels)) && !head_opened
190190
_aprintln(buf, "<thead>", il, ns; minify)
191191
il += 1
192192
head_opened = true

src/backends/html/types.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ Define the style of the tables printed with the HTML back end.
202202
- `source_notes::Vector{HtmlPair}`: Style for the source notes.
203203
"""
204204
@kwdef struct HtmlTableStyle
205-
top_left_string::Vector{HtmlPair} = _HTML__BOLD
205+
top_left_string::Vector{HtmlPair} = _HTML__NO_DECORATION
206206
top_right_string::Vector{HtmlPair} = _HTML__ITALIC
207207
table::Vector{HtmlPair} = _HTML__NO_DECORATION
208208
title::Vector{HtmlPair} = _HTML__XLARGE_BOLD

test/backends/html/alignment.jl

Lines changed: 36 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,15 @@
1010
@testset "Alignment as a Symbol" verbose = true begin
1111
expected = """
1212
<table>
13-
<tr class = "columnLabelRow">
14-
<th style = "text-align: center; font-weight: bold;">Col. 1</th>
15-
<th style = "text-align: center; font-weight: bold;">Col. 2</th>
16-
<th style = "text-align: center; font-weight: bold;">Col. 3</th>
17-
<th style = "text-align: center; font-weight: bold;">Col. 4</th>
18-
<th style = "text-align: center; font-weight: bold;">Col. 5</th>
19-
</tr>
13+
<thead>
14+
<tr class = "columnLabelRow">
15+
<th style = "text-align: center; font-weight: bold;">Col. 1</th>
16+
<th style = "text-align: center; font-weight: bold;">Col. 2</th>
17+
<th style = "text-align: center; font-weight: bold;">Col. 3</th>
18+
<th style = "text-align: center; font-weight: bold;">Col. 4</th>
19+
<th style = "text-align: center; font-weight: bold;">Col. 5</th>
20+
</tr>
21+
</thead>
2022
<tbody>
2123
<tr class = "dataRow">
2224
<td style = "text-align: center;">(1, 1)</td>
@@ -69,13 +71,15 @@
6971

7072
expected = """
7173
<table>
72-
<tr class = "columnLabelRow">
73-
<th style = "font-weight: bold;">Col. 1</th>
74-
<th style = "font-weight: bold;">Col. 2</th>
75-
<th style = "font-weight: bold;">Col. 3</th>
76-
<th style = "font-weight: bold;">Col. 4</th>
77-
<th style = "font-weight: bold;">Col. 5</th>
78-
</tr>
74+
<thead>
75+
<tr class = "columnLabelRow">
76+
<th style = "font-weight: bold;">Col. 1</th>
77+
<th style = "font-weight: bold;">Col. 2</th>
78+
<th style = "font-weight: bold;">Col. 3</th>
79+
<th style = "font-weight: bold;">Col. 4</th>
80+
<th style = "font-weight: bold;">Col. 5</th>
81+
</tr>
82+
</thead>
7983
<tbody>
8084
<tr class = "dataRow">
8185
<td>(1, 1)</td>
@@ -129,13 +133,15 @@
129133
@testset "Alignment as a Vector" verbose = true begin
130134
expected = """
131135
<table>
132-
<tr class = "columnLabelRow">
133-
<th style = "text-align: left; font-weight: bold;">Col. 1</th>
134-
<th style = "text-align: center; font-weight: bold;">Col. 2</th>
135-
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
136-
<th style = "text-align: left; font-weight: bold;">Col. 4</th>
137-
<th style = "text-align: center; font-weight: bold;">Col. 5</th>
138-
</tr>
136+
<thead>
137+
<tr class = "columnLabelRow">
138+
<th style = "text-align: left; font-weight: bold;">Col. 1</th>
139+
<th style = "text-align: center; font-weight: bold;">Col. 2</th>
140+
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
141+
<th style = "text-align: left; font-weight: bold;">Col. 4</th>
142+
<th style = "text-align: center; font-weight: bold;">Col. 5</th>
143+
</tr>
144+
</thead>
139145
<tbody>
140146
<tr class = "dataRow">
141147
<td style = "text-align: left;">(1, 1)</td>
@@ -188,13 +194,15 @@
188194

189195
expected = """
190196
<table>
191-
<tr class = "columnLabelRow">
192-
<th style = "text-align: left; font-weight: bold;">Col. 1</th>
193-
<th style = "text-align: center; font-weight: bold;">Col. 2</th>
194-
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
195-
<th style = "font-weight: bold;">Col. 4</th>
196-
<th style = "text-align: right; font-weight: bold;">Col. 5</th>
197-
</tr>
197+
<thead>
198+
<tr class = "columnLabelRow">
199+
<th style = "text-align: left; font-weight: bold;">Col. 1</th>
200+
<th style = "text-align: center; font-weight: bold;">Col. 2</th>
201+
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
202+
<th style = "font-weight: bold;">Col. 4</th>
203+
<th style = "text-align: right; font-weight: bold;">Col. 5</th>
204+
</tr>
205+
</thead>
198206
<tbody>
199207
<tr class = "dataRow">
200208
<td style = "text-align: left;">(1, 1)</td>

test/backends/html/circular_reference.jl

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@
1717

1818
expected = """
1919
<table>
20-
<tr class = "columnLabelRow">
21-
<th style = "text-align: right; font-weight: bold;">A1</th>
22-
<th style = "text-align: right; font-weight: bold;">A2</th>
23-
<th style = "text-align: right; font-weight: bold;">A3</th>
24-
<th style = "text-align: right; font-weight: bold;">A4</th>
25-
</tr>
20+
<thead>
21+
<tr class = "columnLabelRow">
22+
<th style = "text-align: right; font-weight: bold;">A1</th>
23+
<th style = "text-align: right; font-weight: bold;">A2</th>
24+
<th style = "text-align: right; font-weight: bold;">A3</th>
25+
<th style = "text-align: right; font-weight: bold;">A4</th>
26+
</tr>
27+
</thead>
2628
<tbody>
2729
<tr class = "dataRow">
2830
<td style = "text-align: right;">1</td>

test/backends/html/column_width.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,13 @@
99

1010
expected = """
1111
<table>
12-
<tr class = "columnLabelRow">
13-
<th style = "text-align: right; max-width: 30px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: bold;">Col. 1</th>
14-
<th style = "text-align: right; max-width: 30px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: bold;">Col. 2</th>
15-
<th style = "text-align: right; max-width: 30px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: bold;">Col. 3</th>
16-
</tr>
12+
<thead>
13+
<tr class = "columnLabelRow">
14+
<th style = "text-align: right; max-width: 30px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: bold;">Col. 1</th>
15+
<th style = "text-align: right; max-width: 30px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: bold;">Col. 2</th>
16+
<th style = "text-align: right; max-width: 30px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: bold;">Col. 3</th>
17+
</tr>
18+
</thead>
1719
<tbody>
1820
<tr class = "dataRow">
1921
<td style = "text-align: right; max-width: 30px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">(1, 1)</td>

test/backends/html/cropping.jl

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,14 @@
1616
<div style = "clear: both;"></div>
1717
</div>
1818
<table>
19-
<tr class = "columnLabelRow">
20-
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
21-
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
22-
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
23-
<td>&ctdot;</td>
24-
</tr>
19+
<thead>
20+
<tr class = "columnLabelRow">
21+
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
22+
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
23+
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
24+
<td>&ctdot;</td>
25+
</tr>
26+
</thead>
2527
<tbody>
2628
<tr class = "dataRow">
2729
<td style = "text-align: right;">(1, 1)</td>
@@ -65,12 +67,14 @@
6567
<div style = "clear: both;"></div>
6668
</div>
6769
<table>
68-
<tr class = "columnLabelRow">
69-
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
70-
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
71-
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
72-
<td>&ctdot;</td>
73-
</tr>
70+
<thead>
71+
<tr class = "columnLabelRow">
72+
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
73+
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
74+
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
75+
<td>&ctdot;</td>
76+
</tr>
77+
</thead>
7478
<tbody>
7579
<tr class = "dataRow">
7680
<td style = "text-align: right;">(1, 1)</td>
@@ -109,12 +113,14 @@
109113
@testset "Omitted Cell Summary" begin
110114
expected = """
111115
<table>
112-
<tr class = "columnLabelRow">
113-
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
114-
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
115-
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
116-
<td>&ctdot;</td>
117-
</tr>
116+
<thead>
117+
<tr class = "columnLabelRow">
118+
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
119+
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
120+
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
121+
<td>&ctdot;</td>
122+
</tr>
123+
</thead>
118124
<tbody>
119125
<tr class = "dataRow">
120126
<td style = "text-align: right;">(1, 1)</td>

test/backends/html/default.jl

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,16 @@
1313

1414
expected = """
1515
<table>
16-
<tr class = "columnLabelRow">
17-
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
18-
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
19-
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
20-
<th style = "text-align: right; font-weight: bold;">Col. 4</th>
21-
<th style = "text-align: right; font-weight: bold;">Col. 5</th>
22-
<th style = "text-align: right; font-weight: bold;">Col. 6</th>
23-
</tr>
16+
<thead>
17+
<tr class = "columnLabelRow">
18+
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
19+
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
20+
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
21+
<th style = "text-align: right; font-weight: bold;">Col. 4</th>
22+
<th style = "text-align: right; font-weight: bold;">Col. 5</th>
23+
<th style = "text-align: right; font-weight: bold;">Col. 6</th>
24+
</tr>
25+
</thead>
2426
<tbody>
2527
<tr class = "dataRow">
2628
<td style = "text-align: right;">1</td>

test/backends/html/divs.jl

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@
88
matrix = [1 2]
99

1010
expected = """
11-
<div overflow-x = "scroll">
11+
<div style = "overflow-x: scroll;">
1212
<table class = "myClass">
13-
<tr class = "columnLabelRow">
14-
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
15-
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
16-
</tr>
13+
<thead>
14+
<tr class = "columnLabelRow">
15+
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
16+
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
17+
</tr>
18+
</thead>
1719
<tbody>
1820
<tr class = "dataRow">
1921
<td style = "text-align: right;">1</td>
@@ -36,17 +38,19 @@
3638

3739
expected = """
3840
<div>
39-
<div style = "font-weight: bold; float: left;">
41+
<div style = "float: left;">
4042
<span>Top Left</span>
4143
</div>
4244
<div style = "clear: both;"></div>
4345
</div>
44-
<div overflow-x = "scroll">
46+
<div style = "overflow-x: scroll;">
4547
<table class = "myClass">
46-
<tr class = "columnLabelRow">
47-
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
48-
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
49-
</tr>
48+
<thead>
49+
<tr class = "columnLabelRow">
50+
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
51+
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
52+
</tr>
53+
</thead>
5054
<tbody>
5155
<tr class = "dataRow">
5256
<td style = "text-align: right;">1</td>
@@ -70,20 +74,22 @@
7074

7175
expected = """
7276
<div>
73-
<div style = "font-weight: bold; float: left;">
77+
<div style = "float: left;">
7478
<span>Top Left</span>
7579
</div>
7680
<div style = "font-style: italic; float: right;">
7781
<span>Top Right</span>
7882
</div>
7983
<div style = "clear: both;"></div>
8084
</div>
81-
<div overflow-x = "scroll">
85+
<div style = "overflow-x: scroll;">
8286
<table class = "myClass">
83-
<tr class = "columnLabelRow">
84-
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
85-
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
86-
</tr>
87+
<thead>
88+
<tr class = "columnLabelRow">
89+
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
90+
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
91+
</tr>
92+
</thead>
8793
<tbody>
8894
<tr class = "dataRow">
8995
<td style = "text-align: right;">1</td>

test/backends/html/highlighters.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,13 @@
1212

1313
expected = """
1414
<table>
15-
<tr class = "columnLabelRow">
16-
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
17-
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
18-
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
19-
</tr>
15+
<thead>
16+
<tr class = "columnLabelRow">
17+
<th style = "text-align: right; font-weight: bold;">Col. 1</th>
18+
<th style = "text-align: right; font-weight: bold;">Col. 2</th>
19+
<th style = "text-align: right; font-weight: bold;">Col. 3</th>
20+
</tr>
21+
</thead>
2022
<tbody>
2123
<tr class = "dataRow">
2224
<td style = "text-align: right; font-weight: bold; color: green;">1</td>

test/backends/html/minify.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
matrix = [1 2]
99

1010
expected = """
11-
<table><tr class = "columnLabelRow"><th style = "text-align: right; font-weight: bold;">Col. 1</th><th style = "text-align: right; font-weight: bold;">Col. 2</th></tr><tbody><tr class = "dataRow"><td style = "text-align: right;">1</td><td style = "text-align: right;">2</td></tr></tbody></table>"""
11+
<table><thead><tr class = "columnLabelRow"><th style = "text-align: right; font-weight: bold;">Col. 1</th><th style = "text-align: right; font-weight: bold;">Col. 2</th></tr></thead><tbody><tr class = "dataRow"><td style = "text-align: right;">1</td><td style = "text-align: right;">2</td></tr></tbody></table>"""
1212

1313
result = pretty_table(String, matrix; backend = :html, minify = true)
1414

0 commit comments

Comments
 (0)