Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/theme-css/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ a.headerlink {
visibility: hidden;
}

:is(h1, h2, h3, h4, h5, h6):hover > a.headerlink {
:is(h1, h2, h3, h4, h5, h6, caption):hover > a.headerlink {
visibility: visible;
}

Expand Down
29 changes: 27 additions & 2 deletions layouts/shortcodes/figure.html
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,30 @@
A figure is an image with a caption. Figures may also include a tile, legend, and/or attribution.
'''
legend = '''
**TODO: use tomltotable (https://github.com/scientific-python/scientific-python-hugo-theme/pull/548)**
{{< tomlToTable >}}

[[row]]
column = [
"Project",
"Available Packages",
"Download location"
]

[[row]]
column = [
"NumPy",
"Official *source code* (all platforms) and *binaries* for<br/>\n**Windows**, **Linux**, and **Mac OS X**\n",
"[PyPi page for NumPy](https://pypi.python.org/pypi/numpy)"
]

[[row]]
column = [
"SciPy",
"Official *source code* (all platforms) and *binaries* for<br/>\n**Windows**, **Linux** and **Mac OS X**\n",
"[SciPy release page](https://github.com/scipy/scipy/releases) (sources)<br/>\n[PyPI page for SciPy](https://pypi.python.org/pypi/scipy) (all)\n"
]

{{< /tomlToTable >}}

This paragraph is also part of the legend.
'''
Expand Down Expand Up @@ -59,7 +82,9 @@
</span>
{{- with $figure.legend }}
<div class="legend">
{{ . | markdownify -}}
{{- with (trim . "\n") }}
{{ . | safeHTML }}
{{- end }}
</div>
{{- end }}
</figcaption>
Expand Down
91 changes: 91 additions & 0 deletions layouts/shortcodes/tomlToTable.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
{{/*

doc: Render TOML to an HTML table.

{{< tomlToTable >}}

caption = 'Table caption'
align = ["left", "left", "right"]
width = "80%"
widths = ["10%", "50%", "20%"]
headerrows = 1
footer-rows = 3
stubcolumns = 1

[[row]]
column = [
"Project",
"Available Packages",
"Download location"
]

[[row]]
column = [
"NumPy",
"Official *source code* (all platforms) and *binaries* for<br/>\n**Windows**, **Linux**, and **Mac OS X**\n",
"[PyPi page for NumPy](https://pypi.python.org/pypi/numpy)"
]

[[row]]
column = [
"SciPy",
"Official *source code* (all platforms) and *binaries* for<br/>\n**Windows**, **Linux** and **Mac OS X**\n",
"[SciPy release page](https://github.com/scipy/scipy/releases) (sources)<br/>\n[PyPI page for SciPy](https://pypi.python.org/pypi/scipy) (all)\n"
]

{{< /tomlToTable >}}

*/}}

{{- $data := .Inner | transform.Unmarshal }}
{{- $id := printf "id%03d" $.Ordinal -}}
{{- $align := $data.align }}
{{- $numrows := $data.row | len }}
{{- $headerrows := or $data.headerrows 0 }}
{{- $header := first $headerrows $data.row }}
{{- $body := last (math.Sub $numrows $headerrows) $data.row }}

<table class="table" id="{{ $id }}" {{- with $data.width }}style="width: {{ . }}"{{- end }}>
{{- with $data.caption }}
<caption><span class="caption-text">{{ . }}</span><a class="headerlink" href="#{{ $id }}" title="Link to this table">#</a></caption>
{{- end }}
{{- with $data.widths }}
<colgroup>
{{- range . }}
<col style="width: {{ . }}" />
{{- end }}
</colgroup>
{{ end }}
{{- if $header }}<thead>
{{- range $row_idx, $row := $header }}
{{ if (modBool $row_idx 2) }}<tr class="row-odd">{{- else }}<tr class="row-even">{{- end }}
{{- range $col_idx, $col := $row.column }}
{{- $alignment := or (index $align $col_idx) "left" }}
{{- $isStub := compare.Lt $col_idx $data.stubcolumns }}
{{- $class := cond $isStub "head stub" "head" }}
<th class="{{ $class }}" style="text-align:{{ $alignment }}">
{{ $col | markdownify }}
</th>
{{- end }}
</tr>
{{- end }}
</thead>
{{- end }}
<tbody>
{{- range $row_idx, $row := $body }}
{{ if (modBool (add $row_idx $headerrows) 2) }}<tr class="row-odd">{{- else }}<tr class="row-even">{{- end }}
{{- range $col_idx, $col := $row.column }}
{{- $alignment := or (index $align $col_idx) "left" }}
{{- $isStub := compare.Lt $col_idx $data.stubcolumns }}
{{- if $isStub }}
<th class="stub" style="text-align:{{ $alignment }}">
{{- else }}
<td style="text-align:{{ $alignment }}">
{{- end }}
{{ $col | markdownify }}
{{ cond $isStub "</th>" "</td>" | safeHTML }}
{{- end }}
</tr>
{{- end }}
</tbody>
</table>