Skip to content

Commit

Permalink
Add support for height argument to figure shortcode
Browse files Browse the repository at this point in the history
Fixes #4014
  • Loading branch information
kaushalmodi authored and bep committed Oct 29, 2017
1 parent fdd62eb commit 488631f
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions docs/content/content-management/shortcodes.md
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ The `figure` shortcode can use the following named parameters:
* `attr` (i.e., attribution)
* `attrlink`
* `alt`
* `height`

#### Example `figure` Input

Expand Down
10 changes: 10 additions & 0 deletions hugolib/shortcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion tpl/tplimpl/template_embedded.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" }}
Expand Down

0 comments on commit 488631f

Please sign in to comment.