Skip to content

Commit 161fd9b

Browse files
committed
Add legend to figure using tomlToTable
1 parent 3f0623b commit 161fd9b

File tree

2 files changed

+41
-6
lines changed

2 files changed

+41
-6
lines changed

layouts/shortcodes/figure.html

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,36 @@
1414
A figure is an image with a caption. Figures may also include a tile, legend, and/or attribution.
1515
'''
1616
legend = '''
17-
**TODO: use tomltotable (https://github.com/scientific-python/scientific-python-hugo-theme/pull/548)**
17+
{{< tomlToTable >}}
18+
19+
[[row]]
20+
type = 'header'
21+
22+
[[row.column]]
23+
body = 'Project'
24+
25+
[[row.column]]
26+
body = 'Available Packages'
27+
28+
[[row]]
29+
30+
[[row.column]]
31+
body = 'NumPy'
32+
33+
[[row.column]]
34+
body = '''Official *source code* (all platforms) and *binaries* for<br />
35+
**Windows**, **Linux**, and **Mac OS X**'''
36+
37+
[[row]]
38+
39+
[[row.column]]
40+
body = 'SciPy'
41+
42+
[[row.column]]
43+
body = '''Official *source code* (all platforms) and *binaries* for<br />
44+
**Windows**, **Linux**, and **Mac OS X**'''
45+
46+
{{< /tomlToTable >}}
1847

1948
This paragraph is also part of the legend.
2049
'''
@@ -59,7 +88,9 @@
5988
</span>
6089
{{- with $figure.legend }}
6190
<div class="legend">
62-
{{ . | markdownify -}}
91+
{{- with (trim . "\n") }}
92+
{{ . | safeHTML }}
93+
{{- end }}
6394
</div>
6495
{{- end }}
6596
</figcaption>

layouts/shortcodes/tomlToTable.html

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,12 +50,16 @@
5050
{{ $data := .Inner | transform.Unmarshal }}
5151

5252
{{ with $data }}
53-
<table>
54-
{{ range $row := .row }}
55-
<tr>
53+
<table class="table">
54+
{{ range $i, $row := .row }}
55+
{{if (modBool $i 2)}}
56+
<tr class="row-odd">
57+
{{else}}
58+
<tr class="row-even">
59+
{{end}}
5660
{{ $el := "td" }}
5761
{{ if (eq $row.type "header") }}
58-
{{ $el = "th" }}
62+
{{ $el = "th class='head'" }}
5963
{{ end }}
6064
{{ range $col := .column }}
6165
{{ printf "<%s" $el | safeHTML }} colspan="{{ $col.colspan }}" rowspan="{{ $col.rowspan }}" {{ printf ">" | safeHTML }}

0 commit comments

Comments
 (0)