diff options
author | Kaushal Modi <[email protected]> | 2017-10-27 11:37:54 -0400 |
---|---|---|
committer | Bjørn Erik Pedersen <[email protected]> | 2017-10-29 20:46:57 +0100 |
commit | 488631fe0abc3667355345c7eb98ba7a2204deb5 (patch) | |
tree | 13dc897505ae31a7bddd779e31d626491c813001 | |
parent | fdd62eb4c3dab9229ae4b7aeae45832961f6e168 (diff) | |
download | hugo-488631fe0abc3667355345c7eb98ba7a2204deb5.tar.gz hugo-488631fe0abc3667355345c7eb98ba7a2204deb5.zip |
Add support for height argument to figure shortcode
Fixes #4014
-rw-r--r-- | docs/content/content-management/shortcodes.md | 1 | ||||
-rw-r--r-- | hugolib/shortcode_test.go | 10 | ||||
-rw-r--r-- | tpl/tplimpl/template_embedded.go | 2 |
3 files changed, 12 insertions, 1 deletions
diff --git a/docs/content/content-management/shortcodes.md b/docs/content/content-management/shortcodes.md index fdeb6fba1..e396aada8 100644 --- a/docs/content/content-management/shortcodes.md +++ b/docs/content/content-management/shortcodes.md @@ -88,6 +88,7 @@ The `figure` shortcode can use the following named parameters: * `attr` (i.e., attribution) * `attrlink` * `alt` +* `height` #### Example `figure` Input diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index ab2d1f334..ba0d43c65 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -299,6 +299,16 @@ func TestFigureImgWidth(t *testing.T) { CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="100px" %}}`, "\n<figure class=\"bananas orange\">\n \n <img src=\"/found/here\" alt=\"apple\" width=\"100px\" />\n \n \n</figure>\n", nil) } +func TestFigureImgHeight(t *testing.T) { + t.Parallel() + CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" height="100px" %}}`, "\n<figure class=\"bananas orange\">\n \n <img src=\"/found/here\" alt=\"apple\" height=\"100px\" />\n \n \n</figure>\n", nil) +} + +func TestFigureImgWidthAndHeight(t *testing.T) { + t.Parallel() + CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="50" height="100" %}}`, "\n<figure class=\"bananas orange\">\n \n <img src=\"/found/here\" alt=\"apple\" width=\"50\" height=\"100\" />\n \n \n</figure>\n", nil) +} + const testScPlaceholderRegexp = "HAHAHUGOSHORTCODE-\\d+HBHB" func TestExtractShortcodes(t *testing.T) { diff --git a/tpl/tplimpl/template_embedded.go b/tpl/tplimpl/template_embedded.go index dd3254560..2252d65cf 100644 --- a/tpl/tplimpl/template_embedded.go +++ b/tpl/tplimpl/template_embedded.go @@ -21,7 +21,7 @@ func (t *templateHandler) embedShortcodes() { t.addInternalShortcode("figure.html", `<!-- image --> <figure {{ with .Get "class" }}class="{{.}}"{{ end }}> {{ with .Get "link"}}<a href="{{.}}">{{ end }} - <img src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}" {{ end }}{{ with .Get "width" }}width="{{.}}" {{ end }}/> + <img src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}" {{ end }}{{ with .Get "width" }}width="{{.}}" {{ end }}{{ with .Get "height" }}height="{{.}}" {{ end }}/> {{ if .Get "link"}}</a>{{ end }} {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}} <figcaption>{{ if isset .Params "title" }} |