From 2e95ec6844bf65a25485bdc8e2638e45788f2dcf Mon Sep 17 00:00:00 2001 From: Kaushal Modi Date: Mon, 5 Feb 2018 14:06:29 -0500 Subject: Add "target" and "rel" parameters to figure shortcode Also: - Remove unnecessary space from `figure` tag if no class is specified. - Update related tests. - Add test cases for the changes made to the figure shortcode. - Document the newly added target and rel parameters - Add more detail to the documentation of all figure shortcode parameters. --- hugolib/embedded_shortcodes_test.go | 8 ++++---- hugolib/page_test.go | 2 +- hugolib/shortcode_test.go | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 5 deletions(-) (limited to 'hugolib') diff --git a/hugolib/embedded_shortcodes_test.go b/hugolib/embedded_shortcodes_test.go index 6167cded6..50da35c5b 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 5c8c46c9b..3e9e985e2 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 0b5c29e94..763394032 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) { -- cgit v1.2.3