Add proper table rendering

This commit is contained in:
Francesco 2025-04-18 11:15:18 +02:00
parent fda5cc7355
commit 73e65f2014
2 changed files with 49 additions and 0 deletions

View file

@ -559,6 +559,11 @@ figcaption {
/* Tables */
.table-outer {
width: 100%;
overflow-x: auto;
}
table {
border-collapse: collapse;
margin-top: var(--table-margin-top);

View file

@ -0,0 +1,44 @@
{{/*
Default table rendered plus an outer div to align and overflow tables
accordingly.
Ref: https://gohugo.io/render-hooks/tables/
*/}}
<div class="table-outer">
<table
{{- range $k, $v :=.Attributes }}
{{- if $v }}
{{- printf " %s=%q" $k $v | safeHTMLAttr }}
{{- end }}
{{- end }}>
<thead>
{{- range .THead }}
<tr>
{{- range . }}
<th
{{- with .Alignment }}
{{- printf " style=%q" (printf "text-align: %s" .) |
safeHTMLAttr }}
{{- end -}}>
{{- .Text -}}
</th>
{{- end }}
</tr>
{{- end }}
</thead>
<tbody>
{{- range .TBody }}
<tr>
{{- range . }}
<td
{{- with .Alignment }}
{{- printf " style=%q" (printf "text-align: %s" .) |
safeHTMLAttr }}
{{- end -}}>
{{- .Text -}}
</td>
{{- end }}
</tr>
{{- end }}
</tbody>
</table>
</div>