use table render hook instead of refactor

This commit is contained in:
geekifan
2025-04-28 21:55:12 +08:00
parent 13dc3b9771
commit 483debe717
2 changed files with 39 additions and 8 deletions

View File

@ -0,0 +1,39 @@
<div class="table-wrapper">
<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>

View File

@ -1,13 +1,5 @@
{{ $content := .Content }} {{ $content := .Content }}
<!-- Handle tables -->
{{ if findRE `<table` $content }}
{{ $content = replace $content `<table` `<div class="table-wrapper"><table` }}
{{ $content = replace $content `</table>` `</table></div>` }}
{{ $content = replace $content `<code><div class="table-wrapper">` `<code>` }}
{{ $content = replace $content `</table></div></code>` `</table></code>` }}
{{ end }}
<!-- Change checkbox icons --> <!-- Change checkbox icons -->
{{ if findRE `<input.*type="checkbox"` $content }} {{ if findRE `<input.*type="checkbox"` $content }}
<!-- first replace the li with task-list-item class --> <!-- first replace the li with task-list-item class -->