Last active
January 26, 2023 16:44
-
-
Save exkuretrol/b58cb3592b5cc59a1098423b682d7ce5 to your computer and use it in GitHub Desktop.
A hugo shortcode table, have 3 optional arguments, id, class and title.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{ $htmlTable := .Inner | markdownify }} | |
{{ $label := i18n "table_label" | default "Table" }} | |
{{ $tag := "<table>" }} | |
{{ $newTag := "<table" }} | |
{{ with .Get "id" }} | |
{{ $newTag = printf "<table id='%s'" . }} | |
{{ end }} | |
{{ with .Get "class" }} | |
{{ $newTag = print $newTag " " . }} | |
{{ end }} | |
{{ $newTag = print $newTag " itemscope itemtype='https://schema.org/Table'>" }} | |
{{ with .Get "title" }} | |
{{ $caption := printf "<caption itemprop='about'><strong>%s</strong> %s</caption>" $label . }} | |
{{ $newTag = print $newTag $caption }} | |
{{ end }} | |
{{ $htmlTable := replace $htmlTable $tag $newTag }} | |
{{ $htmlTable | safeHTML }} | |
{{/* inspire by https://gist.github.com/djibe/7a8ba9516f4495dbd6fdf1d1de7a60fe#file-hugo-shortcode-table-html and improved by kuaz */}} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment