ref: 6818170308994b5f01dec7a559f92d6c7c5ca100
parent: c5279064df9664d6b2ad277e2fba1e4bb3b0f4be
author: Kaushal Modi <[email protected]>
date: Tue Oct 2 11:23:10 EDT 2018
Render Markdown in figure shortcode "caption" and "attr" params Fixes https://github.com/gohugoio/hugo/issues/4406.
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -305,6 +305,12 @@
CheckShortCodeMatch(t, `{{< figure src="/found/here" >}}`, "<figure>\n <img src=\"/found/here\"/> \n</figure>", nil)
}
+func TestFigureCaptionAttrWithMarkdown(t *testing.T) {
+ t.Parallel()
+ CheckShortCodeMatch(t, `{{< figure src="/found/here" caption="Something **bold** _italic_" >}}`, "<figure>\n <img src=\"/found/here\"\n alt=\"Something bold italic\"/> <figcaption>\n <p>Something <strong>bold</strong> <em>italic</em></p>\n </figcaption>\n</figure>", nil)
+ CheckShortCodeMatch(t, `{{< figure src="/found/here" attr="Something **bold** _italic_" >}}`, "<figure>\n <img src=\"/found/here\"/> <figcaption>\n <p>Something <strong>bold</strong> <em>italic</em></p>\n </figcaption>\n</figure>", nil)
+}
+
func TestFigureImgWidth(t *testing.T) {
t.Parallel()
CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="100px" %}}`, "<figure class=\"bananas orange\">\n <img src=\"/found/here\"\n alt=\"apple\" width=\"100px\"/> \n</figure>", nil)
--- a/tpl/tplimpl/embedded/templates.autogen.go
+++ b/tpl/tplimpl/embedded/templates.autogen.go
@@ -315,7 +315,7 @@
{{- end }}
<img src="{{ .Get "src" }}"
{{- if or (.Get "alt") (.Get "caption") }}
- alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" }}{{ end }}"
+ alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
{{- end -}}
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
@@ -327,11 +327,11 @@
<h4>{{ . }}</h4>
{{- end -}}
{{- if or (.Get "caption") (.Get "attr") -}}<p>
- {{- .Get "caption" -}}
+ {{- .Get "caption" | markdownify -}}
{{- with .Get "attrlink" -}}
<a href="{{ . }}">
{{- end -}}
- {{- .Get "attr" -}}
+ {{- .Get "attr" | markdownify -}}
{{- if .Get "attrlink" }}</a>{{ end }}</p>
{{- end }}
</figcaption>
--- a/tpl/tplimpl/embedded/templates/shortcodes/figure.html
+++ b/tpl/tplimpl/embedded/templates/shortcodes/figure.html
@@ -4,7 +4,7 @@
{{- end }}
<img src="{{ .Get "src" }}"
{{- if or (.Get "alt") (.Get "caption") }}
- alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" }}{{ end }}"
+ alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" | markdownify| plainify }}{{ end }}"
{{- end -}}
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
@@ -16,11 +16,11 @@
<h4>{{ . }}</h4>
{{- end -}}
{{- if or (.Get "caption") (.Get "attr") -}}<p>
- {{- .Get "caption" -}}
+ {{- .Get "caption" | markdownify -}}
{{- with .Get "attrlink" -}}
<a href="{{ . }}">
{{- end -}}
- {{- .Get "attr" -}}
+ {{- .Get "attr" | markdownify -}}
{{- if .Get "attrlink" }}</a>{{ end }}</p>
{{- end }}
</figcaption>