mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-07 20:30:36 -05:00
Re-organize the figure shortcode for better readability
This commit is contained in:
parent
152cffb13a
commit
c5279064df
5 changed files with 69 additions and 48 deletions
|
@ -123,22 +123,22 @@ func TestShortcodeFigure(t *testing.T) {
|
||||||
}{
|
}{
|
||||||
{
|
{
|
||||||
`{{< figure src="/img/hugo-logo.png" >}}`,
|
`{{< figure src="/img/hugo-logo.png" >}}`,
|
||||||
"(?s)\n<figure>.*?<img src=\"/img/hugo-logo.png\" />.*?</figure>\n",
|
"(?s)<figure>.*?<img src=\"/img/hugo-logo.png\"/>.*?</figure>",
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
// set alt
|
// set alt
|
||||||
`{{< figure src="/img/hugo-logo.png" alt="Hugo logo" >}}`,
|
`{{< figure src="/img/hugo-logo.png" alt="Hugo logo" >}}`,
|
||||||
"(?s)\n<figure>.*?<img src=\"/img/hugo-logo.png\" alt=\"Hugo logo\" />.*?</figure>\n",
|
"(?s)<figure>.*?<img src=\"/img/hugo-logo.png\".+?alt=\"Hugo logo\"/>.*?</figure>",
|
||||||
},
|
},
|
||||||
// set title
|
// set title
|
||||||
{
|
{
|
||||||
`{{< figure src="/img/hugo-logo.png" title="Hugo logo" >}}`,
|
`{{< figure src="/img/hugo-logo.png" title="Hugo logo" >}}`,
|
||||||
"(?s)\n<figure>.*?<img src=\"/img/hugo-logo.png\" />.*?<figcaption>.*?<h4>Hugo logo</h4>.*?</figcaption>.*?</figure>\n",
|
"(?s)<figure>.*?<img src=\"/img/hugo-logo.png\"/>.*?<figcaption>.*?<h4>Hugo logo</h4>.*?</figcaption>.*?</figure>",
|
||||||
},
|
},
|
||||||
// set attr and attrlink
|
// set attr and attrlink
|
||||||
{
|
{
|
||||||
`{{< figure src="/img/hugo-logo.png" attr="Hugo logo" attrlink="/img/hugo-logo.png" >}}`,
|
`{{< figure src="/img/hugo-logo.png" attr="Hugo logo" attrlink="/img/hugo-logo.png" >}}`,
|
||||||
"(?s)\n<figure>.*?<img src=\"/img/hugo-logo.png\" />.*?<figcaption>.*?<p>.*?<a href=\"/img/hugo-logo.png\">.*?Hugo logo.*?</a>.*?</p>.*?</figcaption>.*?</figure>\n",
|
"(?s)<figure>.*?<img src=\"/img/hugo-logo.png\"/>.*?<figcaption>.*?<p>.*?<a href=\"/img/hugo-logo.png\">.*?Hugo logo.*?</a>.*?</p>.*?</figcaption>.*?</figure>",
|
||||||
},
|
},
|
||||||
} {
|
} {
|
||||||
|
|
||||||
|
|
|
@ -792,7 +792,7 @@ func TestPageWithShortCodeInSummary(t *testing.T) {
|
||||||
assertFunc := func(t *testing.T, ext string, pages Pages) {
|
assertFunc := func(t *testing.T, ext string, pages Pages) {
|
||||||
p := pages[0]
|
p := pages[0]
|
||||||
checkPageTitle(t, p, "Simple")
|
checkPageTitle(t, p, "Simple")
|
||||||
checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Next Line. \n<figure>\n \n <img src=\"/not/real\" />\n \n \n</figure>\n.\nMore text here.</p>\n\n<p>Some more text</p>\n"))
|
checkPageContent(t, p, normalizeExpected(ext, "<p>Summary Next Line. <figure> <img src=\"/not/real\"/> </figure> . More text here.</p><p>Some more text</p>"))
|
||||||
checkPageSummary(t, p, "Summary Next Line. . More text here. Some more text")
|
checkPageSummary(t, p, "Summary Next Line. . More text here. Some more text")
|
||||||
checkPageType(t, p, "page")
|
checkPageType(t, p, "page")
|
||||||
}
|
}
|
||||||
|
|
|
@ -255,8 +255,8 @@ This is **plain** text.
|
||||||
|
|
||||||
func TestEmbeddedSC(t *testing.T) {
|
func TestEmbeddedSC(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" %}}`, "\n<figure class=\"bananas orange\">\n \n <img src=\"/found/here\" />\n \n \n</figure>\n", nil)
|
CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" %}}`, "<figure class=\"bananas orange\">\n <img src=\"/found/here\"/> \n</figure>", nil)
|
||||||
CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" caption="This is a caption" %}}`, "\n<figure class=\"bananas orange\">\n \n <img src=\"/found/here\" alt=\"This is a caption\" />\n \n \n <figcaption>\n <p>\n This is a caption\n \n \n \n </p> \n </figcaption>\n \n</figure>\n", nil)
|
CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" caption="This is a caption" %}}`, "<figure class=\"bananas orange\">\n <img src=\"/found/here\"\n alt=\"This is a caption\"/> <figcaption>\n <p>This is a caption</p>\n </figcaption>\n</figure>", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestNestedSC(t *testing.T) {
|
func TestNestedSC(t *testing.T) {
|
||||||
|
@ -302,37 +302,37 @@ func TestParentShortcode(t *testing.T) {
|
||||||
|
|
||||||
func TestFigureOnlySrc(t *testing.T) {
|
func TestFigureOnlySrc(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
CheckShortCodeMatch(t, `{{< figure src="/found/here" >}}`, "\n<figure>\n \n <img src=\"/found/here\" />\n \n \n</figure>\n", nil)
|
CheckShortCodeMatch(t, `{{< figure src="/found/here" >}}`, "<figure>\n <img src=\"/found/here\"/> \n</figure>", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFigureImgWidth(t *testing.T) {
|
func TestFigureImgWidth(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
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)
|
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)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFigureImgHeight(t *testing.T) {
|
func TestFigureImgHeight(t *testing.T) {
|
||||||
t.Parallel()
|
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)
|
CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" height="100px" %}}`, "<figure class=\"bananas orange\">\n <img src=\"/found/here\"\n alt=\"apple\" height=\"100px\"/> \n</figure>", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFigureImgWidthAndHeight(t *testing.T) {
|
func TestFigureImgWidthAndHeight(t *testing.T) {
|
||||||
t.Parallel()
|
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)
|
CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="50" height="100" %}}`, "<figure class=\"bananas orange\">\n <img src=\"/found/here\"\n alt=\"apple\" width=\"50\" height=\"100\"/> \n</figure>", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFigureLinkNoTarget(t *testing.T) {
|
func TestFigureLinkNoTarget(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" >}}`, "\n<figure>\n <a href=\"/jump/here/on/clicking\">\n <img src=\"/found/here\" />\n </a>\n \n</figure>\n", nil)
|
CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" >}}`, "<figure><a href=\"/jump/here/on/clicking\">\n <img src=\"/found/here\"/> </a>\n</figure>", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFigureLinkWithTarget(t *testing.T) {
|
func TestFigureLinkWithTarget(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" target="_self" >}}`, "\n<figure>\n <a href=\"/jump/here/on/clicking\" target=\"_self\">\n <img src=\"/found/here\" />\n </a>\n \n</figure>\n", nil)
|
CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" target="_self" >}}`, "<figure><a href=\"/jump/here/on/clicking\" target=\"_self\">\n <img src=\"/found/here\"/> </a>\n</figure>", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestFigureLinkWithTargetAndRel(t *testing.T) {
|
func TestFigureLinkWithTargetAndRel(t *testing.T) {
|
||||||
t.Parallel()
|
t.Parallel()
|
||||||
CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" target="_blank" rel="noopener" >}}`, "\n<figure>\n <a href=\"/jump/here/on/clicking\" target=\"_blank\" rel=\"noopener\">\n <img src=\"/found/here\" />\n </a>\n \n</figure>\n", nil)
|
CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" target="_blank" rel="noopener" >}}`, "<figure><a href=\"/jump/here/on/clicking\" target=\"_blank\" rel=\"noopener\">\n <img src=\"/found/here\"/> </a>\n</figure>", nil)
|
||||||
}
|
}
|
||||||
|
|
||||||
// #1642
|
// #1642
|
||||||
|
|
45
tpl/tplimpl/embedded/templates.autogen.go
generated
45
tpl/tplimpl/embedded/templates.autogen.go
generated
|
@ -309,24 +309,35 @@ if (!doNotTrack) {
|
||||||
<svg version="1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 61 61"><circle cx="30.5" cy="30.5" r="30.5" opacity=".8" fill="#000"></circle><path d="M25.3 19.2c-2.1-1.2-3.8-.2-3.8 2.2v18.1c0 2.4 1.7 3.4 3.8 2.2l16.6-9.1c2.1-1.2 2.1-3.2 0-4.4l-16.6-9z" fill="#fff"></path></svg>
|
<svg version="1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 61 61"><circle cx="30.5" cy="30.5" r="30.5" opacity=".8" fill="#000"></circle><path d="M25.3 19.2c-2.1-1.2-3.8-.2-3.8 2.2v18.1c0 2.4 1.7 3.4 3.8 2.2l16.6-9.1c2.1-1.2 2.1-3.2 0-4.4l-16.6-9z" fill="#fff"></path></svg>
|
||||||
{{- end -}}
|
{{- end -}}
|
||||||
`},
|
`},
|
||||||
{`shortcodes/figure.html`, `<!-- image -->
|
{`shortcodes/figure.html`, `<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
|
||||||
<figure{{ with .Get "class" }} class="{{.}}"{{ end }}>
|
{{- if .Get "link" -}}
|
||||||
{{ if .Get "link"}}<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>{{ end }}
|
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ 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 }}/>
|
{{- end }}
|
||||||
{{ if .Get "link"}}</a>{{ end }}
|
<img src="{{ .Get "src" }}"
|
||||||
{{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
|
{{- if or (.Get "alt") (.Get "caption") }}
|
||||||
<figcaption>{{ if isset .Params "title" }}
|
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" }}{{ end }}"
|
||||||
<h4>{{ .Get "title" }}</h4>{{ end }}
|
{{- end -}}
|
||||||
{{ if or (.Get "caption") (.Get "attr")}}<p>
|
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
|
||||||
{{ .Get "caption" }}
|
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
|
||||||
{{ with .Get "attrlink"}}<a href="{{.}}"> {{ end }}
|
/> <!-- Closing img tag -->
|
||||||
{{ .Get "attr" }}
|
{{- if .Get "link" }}</a>{{ end -}}
|
||||||
{{ if .Get "attrlink"}}</a> {{ end }}
|
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
|
||||||
</p> {{ end }}
|
<figcaption>
|
||||||
</figcaption>
|
{{ with (.Get "title") -}}
|
||||||
{{ end }}
|
<h4>{{ . }}</h4>
|
||||||
|
{{- end -}}
|
||||||
|
{{- if or (.Get "caption") (.Get "attr") -}}<p>
|
||||||
|
{{- .Get "caption" -}}
|
||||||
|
{{- with .Get "attrlink" -}}
|
||||||
|
<a href="{{ . }}">
|
||||||
|
{{- end -}}
|
||||||
|
{{- .Get "attr" -}}
|
||||||
|
{{- if .Get "attrlink" }}</a>{{ end }}</p>
|
||||||
|
{{- end }}
|
||||||
|
</figcaption>
|
||||||
|
{{- end }}
|
||||||
</figure>
|
</figure>
|
||||||
<!-- image -->`},
|
`},
|
||||||
{`shortcodes/gist.html`, `<script type="application/javascript" src="//gist.github.com/{{ index .Params 0 }}/{{ index .Params 1 }}.js{{if len .Params | eq 3 }}?file={{ index .Params 2 }}{{end}}"></script>`},
|
{`shortcodes/gist.html`, `<script type="application/javascript" src="//gist.github.com/{{ index .Params 0 }}/{{ index .Params 1 }}.js{{if len .Params | eq 3 }}?file={{ index .Params 2 }}{{end}}"></script>`},
|
||||||
{`shortcodes/highlight.html`, `{{ if len .Params | eq 2 }}{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}{{ else }}{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}{{ end }}`},
|
{`shortcodes/highlight.html`, `{{ if len .Params | eq 2 }}{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}{{ else }}{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}{{ end }}`},
|
||||||
{`shortcodes/instagram.html`, `{{- $pc := .Page.Site.Config.Privacy.Instagram -}}
|
{`shortcodes/instagram.html`, `{{- $pc := .Page.Site.Config.Privacy.Instagram -}}
|
||||||
|
|
|
@ -1,18 +1,28 @@
|
||||||
<!-- image -->
|
<figure{{ with .Get "class" }} class="{{ . }}"{{ end }}>
|
||||||
<figure{{ with .Get "class" }} class="{{.}}"{{ end }}>
|
{{- if .Get "link" -}}
|
||||||
{{ if .Get "link"}}<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ end }}>{{ end }}
|
<a href="{{ .Get "link" }}"{{ with .Get "target" }} target="{{ . }}"{{ end }}{{ with .Get "rel" }} rel="{{ . }}"{{ 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 }}/>
|
{{- end }}
|
||||||
{{ if .Get "link"}}</a>{{ end }}
|
<img src="{{ .Get "src" }}"
|
||||||
{{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}
|
{{- if or (.Get "alt") (.Get "caption") }}
|
||||||
<figcaption>{{ if isset .Params "title" }}
|
alt="{{ with .Get "alt" }}{{ . }}{{ else }}{{ .Get "caption" }}{{ end }}"
|
||||||
<h4>{{ .Get "title" }}</h4>{{ end }}
|
{{- end -}}
|
||||||
{{ if or (.Get "caption") (.Get "attr")}}<p>
|
{{- with .Get "width" }} width="{{ . }}"{{ end -}}
|
||||||
{{ .Get "caption" }}
|
{{- with .Get "height" }} height="{{ . }}"{{ end -}}
|
||||||
{{ with .Get "attrlink"}}<a href="{{.}}"> {{ end }}
|
/> <!-- Closing img tag -->
|
||||||
{{ .Get "attr" }}
|
{{- if .Get "link" }}</a>{{ end -}}
|
||||||
{{ if .Get "attrlink"}}</a> {{ end }}
|
{{- if or (or (.Get "title") (.Get "caption")) (.Get "attr") -}}
|
||||||
</p> {{ end }}
|
<figcaption>
|
||||||
</figcaption>
|
{{ with (.Get "title") -}}
|
||||||
{{ end }}
|
<h4>{{ . }}</h4>
|
||||||
|
{{- end -}}
|
||||||
|
{{- if or (.Get "caption") (.Get "attr") -}}<p>
|
||||||
|
{{- .Get "caption" -}}
|
||||||
|
{{- with .Get "attrlink" -}}
|
||||||
|
<a href="{{ . }}">
|
||||||
|
{{- end -}}
|
||||||
|
{{- .Get "attr" -}}
|
||||||
|
{{- if .Get "attrlink" }}</a>{{ end }}</p>
|
||||||
|
{{- end }}
|
||||||
|
</figcaption>
|
||||||
|
{{- end }}
|
||||||
</figure>
|
</figure>
|
||||||
<!-- image -->
|
|
Loading…
Reference in a new issue