Render Markdown in figure shortcode "caption" and "attr" params
authorKaushal Modi <kaushal.modi@gmail.com>
Tue, 2 Oct 2018 19:23:10 +0000 (15:23 -0400)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Wed, 3 Oct 2018 06:55:53 +0000 (09:55 +0300)
Fixes https://github.com/gohugoio/hugo/issues/4406.

hugolib/shortcode_test.go
tpl/tplimpl/embedded/templates.autogen.go
tpl/tplimpl/embedded/templates/shortcodes/figure.html

index 084662b7af65cc25c22db7a9d8fa235fc6b4b13d..df7b7103f9894f00dece5c039817947d91cde4a8 100644 (file)
@@ -305,6 +305,12 @@ func TestFigureOnlySrc(t *testing.T) {
        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)
index 23f3cfe84e80cffcfc25dd476213c34e164975a5..2b36ae37b7eaadaadfb78585a2b4f4851a310734 100644 (file)
@@ -315,7 +315,7 @@ if (!doNotTrack) {
     {{- 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 @@ if (!doNotTrack) {
                 <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>
index 9fa847eaa6606f729820f74ecdbb70f827f5922f..2da48ca8fc15a175162d6cd07eb82cc012252df8 100644 (file)
@@ -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 -}}
                 <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>