Merge pull request #120 from tomfran/feature/tables_render

Add proper table rendering
This commit is contained in:
Francesco Tomaselli 2025-04-18 11:17:00 +02:00 committed by GitHub
commit 12f3659ed9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
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>