How to Customise Tables

Hi, I would like to enhance answer by @zwbetz in order to fix wrong Goldmark td align attribute thanks to ReplaceRE function. My table shortcut is like this and now my table will render like this awesome Bootstrap theme .

{{ $htmlTable := .Inner | markdownify }}
{{ $class := .Get 0 }}
{{ $old := "<table>" }}
{{ $new := printf "<table class=\"%s\">" $class }}
{{ $htmlTable := replace $htmlTable $old $new }}
{{ $htmlTable := replaceRE "align=\"([a-z]+)\"" "style=\"text-align: $1\"" $htmlTable}}

<div class="data-table">
  {{ $htmlTable | safeHTML }}
</div>

<!-- Inspired by https://zwbetz.com/style-a-markdown-table-with-bootstrap-classes-in-hugo/ -->
1 Like