From e27cbaca79fc28f271ccce595dd7ef822017a833 Mon Sep 17 00:00:00 2001 From: George Cushen Date: Sun, 21 Feb 2021 21:24:03 +0000 Subject: [PATCH] feat: enable Figure to be nested within a `{{%` Markdown shortcode Based on user request to parse both Markdown and nested HTML shortcodes (Figures) within Callout shortcode: https://discord.com/channels/722225264733716590/742863504515793149/813105748283883570 Uses `{{-` to unindent HTML so that Figure shortcode can be nested within a `{{%` Markdown shortcode, such as Callout, without the HTML being rendered as a Markdown code block. This way we utilise Hugo's HTML in Markdown approach (aka Goldmark `unsafe`) rather than separating HTML from Markdown. Previously, Figure could only be nested within a `{{<` HTML shortcode. --- wowchemy/layouts/shortcodes/callout.html | 2 +- wowchemy/layouts/shortcodes/figure.html | 12 +++++++----- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/wowchemy/layouts/shortcodes/callout.html b/wowchemy/layouts/shortcodes/callout.html index f509381c..e1a41b27 100644 --- a/wowchemy/layouts/shortcodes/callout.html +++ b/wowchemy/layouts/shortcodes/callout.html @@ -1,5 +1,5 @@
- {{ .Inner }} + {{ .Inner | markdownify | emojify }}
diff --git a/wowchemy/layouts/shortcodes/figure.html b/wowchemy/layouts/shortcodes/figure.html index ad90c873..00b23cc0 100644 --- a/wowchemy/layouts/shortcodes/figure.html +++ b/wowchemy/layouts/shortcodes/figure.html @@ -1,5 +1,7 @@ {{/* Figure Shortcode for Wowchemy. */}} {{/* Load image from page dir falling back to media library at `assets/media/` and then to remote URI. */}} +{{/* Note: Uses `{{-` to unindent HTML so that Figure shortcode can be nested within a `{{%` Markdown shortcode, + such as Callout, without the HTML being rendered as a Markdown code block. */}} {{ $destination := .Get "src" }} {{ $caption := .Get "caption" | default (.Get "title") | default "" }}{{/* Support legacy `title` option. */}} @@ -16,13 +18,13 @@ {{- if $img -}} {{ $isSVG := eq $img.MediaType.SubType "svg" }} - {{ if $isSVG }} + {{ if $isSVG -}} {{ $alt }} - {{ else }} + {{- else }} {{- $img_lg := $img.Fit "1200x1200" -}} {{- $img_md := $img_lg.Fit "760x760" -}}{{/* Match `.docs-article-container` max-width */}} {{- $img_sm := $img_md.Fit "400x400" -}} @@ -37,7 +39,7 @@ height="{{ $height }}" loading="lazy" {{ if $zoom }}data-zoomable{{end}} /> - {{ end }} + {{- end }} {{- else -}} {{ $alt }} @@ -45,9 +47,9 @@ {{ if $caption }} {{/* Localize the figure numbering (if enabled). */}} - {{ $figure := split (i18n "figure" | default "Figure %d:") "%d" }} + {{- $figure := split (i18n "figure" | default "Figure %d:") "%d" -}} {{ $caption | markdownify | emojify }} - {{ end }} + {{- end -}}