Advanced markdown table layout renderer

Thanks.

Improved table render is:

{{ $tnumber := add 1 $.Ordinal }}
{{- $userClass := .Attributes.class | default "" }}
{{ with .Attributes.caption }}<script type="application/ld+json">{"@context": "https://schema.org","@type": "Table","about": "{{ . | $.Page.RenderString }}"}</script>{{ end }}
<section class="data-table" tabindex="0" {{ with .Attributes.caption }}aria-labelledby="caption-{{ $tnumber }}" {{ end }}>
<table class="table {{ if $userClass }} {{ $userClass }}{{ end }}"
    {{- range $k, $v := .Attributes }}
      {{- if and $v (ne $k "caption") (ne $k "class") }}
        {{- printf " %s=%q" $k $v | safeHTMLAttr }}
      {{- end }}
    {{- end }}>
  {{- with .Attributes.caption }}
  <caption id="caption-{{ $tnumber }}">
    <strong>Tableau {{ $tnumber }}.</strong> {{ . | $.Page.RenderString  }}.
  </caption>
  {{- end }}
  <thead>
    {{- range .THead }}
      <tr>
        {{- range . }}
          <th scope="col"
            {{- with .Alignment }}
              {{- printf " style=%q" (printf "text-align: %s" .) | safeHTMLAttr }}
            {{- end -}}
          >
            {{- .Text -}}
          </th>
        {{- end }}
      </tr>
    {{- end }}
  </thead>
  <tbody>
    {{- range .TBody }}
      <tr>
        {{- range first 1 . }}
          <th scope="row"
            {{- with .Alignment }}
              {{- printf " style=%q" (printf "text-align: %s" .) | safeHTMLAttr }}
            {{- end -}}
          >
            {{- .Text -}}
          </th>
        {{- end }}
        {{- range after 1 . }}
          <td
            {{- with .Alignment }}
              {{- printf " style=%q" (printf "text-align: %s" .) | safeHTMLAttr }}
            {{- end -}}
          >
            {{- .Text -}}
          </td>
        {{- end }}
      </tr>
    {{- end }}
  </tbody>
</table>
</section>
2 Likes