HomeBikeshedComponents

figure.html and figcaption.html Shortcodes

Published:

Though the <figure>/<figcaption> elements are typically used for annotated images, but they don’t have to be. Instead of assuming that figures will always be images, this lets you specify markdown between a {{% figure %}}/{{% figcaption %}} block along with optional attributes for the respective HTML elements.

Source Code

Except for the tag name, these shortcodes are the exact same. I’m wondering if I should just make a generic block shortcode which just changes the tag name.

figure.html

<figure{{ range $attr, $val := .Params }} {{ print $attr | safeHTMLAttr }}{{ if ne $val "" }}{{ print `="` $val `"` | safeHTMLAttr }}{{ end }}{{ end }}>
{{ .Inner }}
</figure>

figcaption.html

<figcaption{{ range $attr, $val := .Params }} {{ print $attr | safeHTMLAttr }}{{ if ne $val "" }}{{ print `="` $val `"` | safeHTMLAttr }}{{ end }}{{ end }}>
{{ .Inner }}
</figcaption>