From 6818170308994b5f01dec7a559f92d6c7c5ca100 Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Tue, 2 Oct 2018 15:23:10 -0400 Subject: [PATCH] Render Markdown in figure shortcode "caption" and "attr" params Fixes https://github.com/gohugoio/hugo/issues/4406. --- hugolib/shortcode_test.go | 6 ++++++ tpl/tplimpl/embedded/templates.autogen.go | 6 +++--- tpl/tplimpl/embedded/templates/shortcodes/figure.html | 6 +++--- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 084662b7a..df7b7103f 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -305,6 +305,12 @@ func TestFigureOnlySrc(t *testing.T) { CheckShortCodeMatch(t, `{{< figure src="/found/here" >}}`, "
\n \n
", nil) } +func TestFigureCaptionAttrWithMarkdown(t *testing.T) { + t.Parallel() + CheckShortCodeMatch(t, `{{< figure src="/found/here" caption="Something **bold** _italic_" >}}`, "
\n \"Something
\n

Something bold italic

\n
\n
", nil) + CheckShortCodeMatch(t, `{{< figure src="/found/here" attr="Something **bold** _italic_" >}}`, "
\n
\n

Something bold italic

\n
\n
", nil) +} + func TestFigureImgWidth(t *testing.T) { t.Parallel() CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="100px" %}}`, "
\n \"apple\" \n
", nil) diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index 23f3cfe84..2b36ae37b 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -315,7 +315,7 @@ if (!doNotTrack) { {{- end }} {{ with .Get {{ . }} {{- end -}} {{- if or (.Get "caption") (.Get "attr") -}}

- {{- .Get "caption" -}} + {{- .Get "caption" | markdownify -}} {{- with .Get "attrlink" -}} {{- end -}} - {{- .Get "attr" -}} + {{- .Get "attr" | markdownify -}} {{- if .Get "attrlink" }}{{ end }}

{{- end }} diff --git a/tpl/tplimpl/embedded/templates/shortcodes/figure.html b/tpl/tplimpl/embedded/templates/shortcodes/figure.html index 9fa847eaa..2da48ca8f 100644 --- a/tpl/tplimpl/embedded/templates/shortcodes/figure.html +++ b/tpl/tplimpl/embedded/templates/shortcodes/figure.html @@ -4,7 +4,7 @@ {{- end }} {{ with .Get {{ . }} {{- end -}} {{- if or (.Get "caption") (.Get "attr") -}}

- {{- .Get "caption" -}} + {{- .Get "caption" | markdownify -}} {{- with .Get "attrlink" -}} {{- end -}} - {{- .Get "attr" -}} + {{- .Get "attr" | markdownify -}} {{- if .Get "attrlink" }}{{ end }}

{{- end }}