diff --git a/docs/content/content-management/shortcodes.md b/docs/content/content-management/shortcodes.md index b6428f5a..e5bc8526 100644 --- a/docs/content/content-management/shortcodes.md +++ b/docs/content/content-management/shortcodes.md @@ -80,15 +80,41 @@ Hugo ships with a set of predefined shortcodes that represent very common usage. The `figure` shortcode can use the following named parameters: -* `src` -* `link` -* `title` -* `caption` -* `class` -* `attr` (i.e., attribution) -* `attrlink` -* `alt` -* `width` +src +: URL of the image to be displayed. + +link +: If the image needs to be hyperlinked, URL of the destination. + +target +: Optional `target` attribute for the URL if `link` parameter is set. + +rel +: Optional `rel` attribute for the URL if `link` parameter is set. + +alt +: Alternate text for the image if the image cannot be displayed. + +title +: Image title. + +caption +: Image caption. + +class +: `class` attribute of the HTML `figure` tag. + +height +: `height` attribute of the image. + +width +: `width` attribute of the image. + +attr +: Image attribution text. + +attrlink +: If the attribution text needs to be hyperlinked, URL of the destination. #### Example `figure` Input diff --git a/docs/content/templates/shortcode-templates.md b/docs/content/templates/shortcode-templates.md index de159428..08f1b4c8 100644 --- a/docs/content/templates/shortcode-templates.md +++ b/docs/content/templates/shortcode-templates.md @@ -218,7 +218,7 @@ You have created the shortcode at `/layouts/shortcodes/img.html`, which loads th Would be rendered as: {{< code file="img-output.html" copy="false" >}} -
+

Steve Francia

diff --git a/hugolib/embedded_shortcodes_test.go b/hugolib/embedded_shortcodes_test.go index 6167cded..50da35c5 100644 --- a/hugolib/embedded_shortcodes_test.go +++ b/hugolib/embedded_shortcodes_test.go @@ -123,22 +123,22 @@ func TestShortcodeFigure(t *testing.T) { }{ { `{{< figure src="/img/hugo-logo.png" >}}`, - "(?s)\n
.*?.*?
\n", + "(?s)\n
.*?.*?
\n", }, { // set alt `{{< figure src="/img/hugo-logo.png" alt="Hugo logo" >}}`, - "(?s)\n
.*?\"Hugo.*?
\n", + "(?s)\n
.*?\"Hugo.*?
\n", }, // set title { `{{< figure src="/img/hugo-logo.png" title="Hugo logo" >}}`, - "(?s)\n
.*?.*?
.*?

Hugo logo

.*?
.*?
\n", + "(?s)\n
.*?.*?
.*?

Hugo logo

.*?
.*?
\n", }, // set attr and attrlink { `{{< figure src="/img/hugo-logo.png" attr="Hugo logo" attrlink="/img/hugo-logo.png" >}}`, - "(?s)\n
.*?.*?
.*?

.*?.*?Hugo logo.*?.*?

.*?
.*?
\n", + "(?s)\n
.*?.*?
.*?

.*?.*?Hugo logo.*?.*?

.*?
.*?
\n", }, } { diff --git a/hugolib/page_test.go b/hugolib/page_test.go index 5c8c46c9..3e9e985e 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -789,7 +789,7 @@ func TestPageWithShortCodeInSummary(t *testing.T) { assertFunc := func(t *testing.T, ext string, pages Pages) { p := pages[0] checkPageTitle(t, p, "Simple") - checkPageContent(t, p, normalizeExpected(ext, "

Summary Next Line. \n

\n \n \n \n \n
\n.\nMore text here.

\n\n

Some more text

\n")) + checkPageContent(t, p, normalizeExpected(ext, "

Summary Next Line. \n

\n \n \n \n \n
\n.\nMore text here.

\n\n

Some more text

\n")) checkPageSummary(t, p, "Summary Next Line. . More text here. Some more text") checkPageType(t, p, "page") } diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 0b5c29e9..76339403 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -293,6 +293,11 @@ func TestParentShortcode(t *testing.T) { } +func TestFigureOnlySrc(t *testing.T) { + t.Parallel() + CheckShortCodeMatch(t, `{{< figure src="/found/here" >}}`, "\n
\n \n \n \n \n
\n", nil) +} + func TestFigureImgWidth(t *testing.T) { t.Parallel() CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="100px" %}}`, "\n
\n \n \"apple\"\n \n \n
\n", nil) @@ -308,6 +313,21 @@ func TestFigureImgWidthAndHeight(t *testing.T) { CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="50" height="100" %}}`, "\n
\n \n \"apple\"\n \n \n
\n", nil) } +func TestFigureLinkNoTarget(t *testing.T) { + t.Parallel() + CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" >}}`, "\n
\n \n \n \n \n
\n", nil) +} + +func TestFigureLinkWithTarget(t *testing.T) { + t.Parallel() + CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" target="_self" >}}`, "\n
\n \n \n \n \n
\n", nil) +} + +func TestFigureLinkWithTargetAndRel(t *testing.T) { + t.Parallel() + CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" target="_blank" rel="noopener" >}}`, "\n
\n \n \n \n \n
\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 627d4dc4..18bba44f 100644 --- a/tpl/tplimpl/template_embedded.go +++ b/tpl/tplimpl/template_embedded.go @@ -19,8 +19,8 @@ func (t *templateHandler) embedShortcodes() { t.addInternalShortcode("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 }}`) t.addInternalShortcode("test.html", `This is a simple Test`) t.addInternalShortcode("figure.html", ` -
- {{ with .Get "link"}}{{ end }} + + {{ if .Get "link"}}{{ end }} {{ if .Get "link"}}{{ end }} {{ if or (or (.Get "title") (.Get "caption")) (.Get "attr")}}