{{ $htmlTable := .Inner | markdownify }}
{{ $old := "<table>" }}
{{ $new := "" }}
{{ $title := .Get "title" | markdownify }}
{{ $extraClass := .Get "class" }}
<!-- Generate a random id for the table (a11y purpose) -->
{{ $id := "" }}
  {{ with .Get "id" }}
    {{ $id = . }}
  {{ else }}
  {{ $id = delimit (shuffle (seq 1 9)) "" }}
  {{ $id = printf "t-%s"  $id}}
  {{ end }}

{{ if $title }}
  {{ $new = printf "<table class=\"table %s\" id=\"%s\" itemscope itemtype=\"https://schema.org/Table\"><caption id=\"table-caption-%s\" itemprop=\"about\"><b>Tableau.</b> %s</caption>" $extraClass $id $id $title | markdownify }}
{{ else }}
  {{ $new = printf "<table class=\"table %s\" id=\"%s\">" $extraClass $id}}
{{ end }}
{{ $htmlTable := replace $htmlTable $old $new }}
{{ $htmlTable := replaceRE "align=\"([a-z]+)\"" "style=\"text-align: $1\"" $htmlTable }}

<div class="data-table" role="region" tabindex="0" {{ if $title }}{{ printf "aria-labelledby=\"table-caption-%s\"" $id | safeHTMLAttr }}{{ end }}>
  {{ $htmlTable | safeHTML }}
</div>
<!-- {{ if $title }}<script type="application/ld+json">{"@context": "https://schema.org","@type": "Table","about": "{{ printf "%s" $title | plainify }}"}</script>{{ end }}-->
<!-- Inspired by https://zwbetz.com/style-a-markdown-table-with-bootstrap-classes-in-hugo/ and improved by djibe-->
<!-- Features: HTML5 compatibility (no align-*), markdown alignment, Bootstrap 4/5 compatibility, <caption> support, JSON+LD + Schema.org markup, WAI accessibility, custom CSS, custom Id, responsive (with CSS) -->