Skip to content

Commit 488631f

Browse files
kaushalmodibep
authored andcommitted
Add support for height argument to figure shortcode
Fixes #4014
1 parent fdd62eb commit 488631f

File tree

3 files changed

+12
-1
lines changed

3 files changed

+12
-1
lines changed

‎docs/content/content-management/shortcodes.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ The `figure` shortcode can use the following named parameters:
8888
* `attr` (i.e., attribution)
8989
* `attrlink`
9090
* `alt`
91+
* `height`
9192

9293
#### Example `figure` Input
9394

‎hugolib/shortcode_test.go‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,16 @@ func TestFigureImgWidth(t *testing.T) {
299299
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)
300300
}
301301

302+
func TestFigureImgHeight(t *testing.T) {
303+
t.Parallel()
304+
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)
305+
}
306+
307+
func TestFigureImgWidthAndHeight(t *testing.T) {
308+
t.Parallel()
309+
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)
310+
}
311+
302312
const testScPlaceholderRegexp = "HAHAHUGOSHORTCODE-\\d+HBHB"
303313

304314
func TestExtractShortcodes(t *testing.T) {

‎tpl/tplimpl/template_embedded.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ func (t *templateHandler) embedShortcodes() {
2121
t.addInternalShortcode("figure.html", `<!-- image -->
2222
<figure {{ with .Get "class" }}class="{{.}}"{{ end }}>
2323
{{ with .Get "link"}}<a href="{{.}}">{{ end }}
24-
<img src="{{ .Get "src" }}" {{ if or (.Get "alt") (.Get "caption") }}alt="{{ with .Get "alt"}}{{.}}{{else}}{{ .Get "caption" }}{{ end }}" {{ end }}{{ with .Get "width" }}width="{{.}}" {{ end }}/>
24+
<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 }}/>
2525
{{ if .Get "link"}}</a>{{ end }}
2626
{{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
2727
<figcaption>{{ if isset .Params "title" }}

0 commit comments

Comments
 (0)