Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-28 12:01:47 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-29 12:50:58 +0300
commit0f8dc47037f59156c04540d97ed1b588e6bc1164 (patch)
tree78d76bb4d52b2f35b609013fde6ec4f5e19730c8 /hugolib/shortcode_test.go
parent3b478f50b7408ad78d085fa6dbc3c7a683c9d943 (diff)
Remove Blackfriday markdown engine
It has been deprecated for a long time, its v1 version is not maintained anymore, and there are many known issues. Goldmark should be a mature replacement by now. Closes #9934
Diffstat (limited to 'hugolib/shortcode_test.go')
-rw-r--r--hugolib/shortcode_test.go563
1 files changed, 11 insertions, 552 deletions
diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go
index d1a844423..e9af2371f 100644
--- a/hugolib/shortcode_test.go
+++ b/hugolib/shortcode_test.go
@@ -21,332 +21,13 @@ import (
"testing"
"github.com/gohugoio/hugo/config"
- "github.com/gohugoio/hugo/markup/asciidocext"
- "github.com/gohugoio/hugo/markup/rst"
"github.com/gohugoio/hugo/parser/pageparser"
"github.com/gohugoio/hugo/resources/page"
- "github.com/gohugoio/hugo/deps"
- "github.com/gohugoio/hugo/tpl"
- "github.com/spf13/cast"
-
qt "github.com/frankban/quicktest"
)
-func CheckShortCodeMatch(t *testing.T, input, expected string, withTemplate func(templ tpl.TemplateManager) error) {
- t.Helper()
- CheckShortCodeMatchAndError(t, input, expected, withTemplate, false)
-}
-
-func CheckShortCodeMatchAndError(t *testing.T, input, expected string, withTemplate func(templ tpl.TemplateManager) error, expectError bool) {
- t.Helper()
- cfg, fs := newTestCfg()
-
- cfg.Set("markup", map[string]any{
- "defaultMarkdownHandler": "blackfriday", // TODO(bep)
- })
-
- c := qt.New(t)
-
- // Need some front matter, see https://github.com/gohugoio/hugo/issues/2337
- contentFile := `---
-title: "Title"
----
-` + input
-
- writeSource(t, fs, "content/simple.md", contentFile)
-
- b := newTestSitesBuilderFromDepsCfg(t, deps.DepsCfg{Fs: fs, Cfg: cfg, WithTemplate: withTemplate}).WithNothingAdded()
- err := b.BuildE(BuildCfg{})
-
- if err != nil && !expectError {
- t.Fatalf("Shortcode rendered error %s.", err)
- }
-
- if expectError {
- c.Assert(err, qt.ErrorMatches, expected)
- return
- }
-
- h := b.H
- c.Assert(len(h.Sites), qt.Equals, 1)
-
- c.Assert(len(h.Sites[0].RegularPages()), qt.Equals, 1)
-
- output := strings.TrimSpace(content(h.Sites[0].RegularPages()[0]))
- output = strings.TrimPrefix(output, "<p>")
- output = strings.TrimSuffix(output, "</p>")
-
- expected = strings.TrimSpace(expected)
-
- if output != expected {
- t.Fatalf("Shortcode render didn't match. got \n%q but expected \n%q", output, expected)
- }
-}
-
-func TestNonSC(t *testing.T) {
- t.Parallel()
- // notice the syntax diff from 0.12, now comment delims must be added
- CheckShortCodeMatch(t, "{{%/* movie 47238zzb */%}}", "{{% movie 47238zzb %}}", nil)
-}
-
-// Issue #929
-func TestHyphenatedSC(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/hyphenated-video.html", `Playing Video {{ .Get 0 }}`)
- return nil
- }
-
- CheckShortCodeMatch(t, "{{< hyphenated-video 47238zzb >}}", "Playing Video 47238zzb", wt)
-}
-
-// Issue #1753
-func TestNoTrailingNewline(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/a.html", `{{ .Get 0 }}`)
- return nil
- }
-
- CheckShortCodeMatch(t, "ab{{< a c >}}d", "abcd", wt)
-}
-
-func TestPositionalParamSC(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/video.html", `Playing Video {{ .Get 0 }}`)
- return nil
- }
-
- CheckShortCodeMatch(t, "{{< video 47238zzb >}}", "Playing Video 47238zzb", wt)
- CheckShortCodeMatch(t, "{{< video 47238zzb 132 >}}", "Playing Video 47238zzb", wt)
- CheckShortCodeMatch(t, "{{<video 47238zzb>}}", "Playing Video 47238zzb", wt)
- CheckShortCodeMatch(t, "{{<video 47238zzb >}}", "Playing Video 47238zzb", wt)
- CheckShortCodeMatch(t, "{{< video 47238zzb >}}", "Playing Video 47238zzb", wt)
-}
-
-func TestPositionalParamIndexOutOfBounds(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/video.html", `Playing Video {{ with .Get 1 }}{{ . }}{{ else }}Missing{{ end }}`)
- return nil
- }
- CheckShortCodeMatch(t, "{{< video 47238zzb >}}", "Playing Video Missing", wt)
-}
-
-// #5071
-func TestShortcodeRelated(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/a.html", `{{ len (.Site.RegularPages.Related .Page) }}`)
- return nil
- }
-
- CheckShortCodeMatch(t, "{{< a >}}", "0", wt)
-}
-
-func TestShortcodeInnerMarkup(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("shortcodes/a.html", `<div>{{ .Inner }}</div>`)
- tem.AddTemplate("shortcodes/b.html", `**Bold**: <div>{{ .Inner }}</div>`)
- return nil
- }
-
- CheckShortCodeMatch(t,
- "{{< a >}}B: <div>{{% b %}}**Bold**{{% /b %}}</div>{{< /a >}}",
- // This assertion looks odd, but is correct: for inner shortcodes with
- // the {{% we treats the .Inner content as markup, but not the shortcode
- // itself.
- "<div>B: <div>**Bold**: <div><strong>Bold</strong></div></div></div>",
- wt)
-
- CheckShortCodeMatch(t,
- "{{% b %}}This is **B**: {{< b >}}This is B{{< /b>}}{{% /b %}}",
- "<strong>Bold</strong>: <div>This is <strong>B</strong>: <strong>Bold</strong>: <div>This is B</div></div>",
- wt)
-}
-
-// some repro issues for panics in Go Fuzz testing
-
-func TestNamedParamSC(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/img.html", `<img{{ with .Get "src" }} src="{{.}}"{{end}}{{with .Get "class"}} class="{{.}}"{{end}}>`)
- return nil
- }
- CheckShortCodeMatch(t, `{{< img src="one" >}}`, `<img src="one">`, wt)
- CheckShortCodeMatch(t, `{{< img class="aspen" >}}`, `<img class="aspen">`, wt)
- CheckShortCodeMatch(t, `{{< img src= "one" >}}`, `<img src="one">`, wt)
- CheckShortCodeMatch(t, `{{< img src ="one" >}}`, `<img src="one">`, wt)
- CheckShortCodeMatch(t, `{{< img src = "one" >}}`, `<img src="one">`, wt)
- CheckShortCodeMatch(t, `{{< img src = "one" class = "aspen grove" >}}`, `<img src="one" class="aspen grove">`, wt)
-}
-
-// Issue #2294
-func TestNestedNamedMissingParam(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/acc.html", `<div class="acc">{{ .Inner }}</div>`)
- tem.AddTemplate("_internal/shortcodes/div.html", `<div {{with .Get "class"}} class="{{ . }}"{{ end }}>{{ .Inner }}</div>`)
- tem.AddTemplate("_internal/shortcodes/div2.html", `<div {{with .Get 0}} class="{{ . }}"{{ end }}>{{ .Inner }}</div>`)
- return nil
- }
- CheckShortCodeMatch(t,
- `{{% acc %}}{{% div %}}d1{{% /div %}}{{% div2 %}}d2{{% /div2 %}}{{% /acc %}}`,
- "<div class=\"acc\"><div >d1</div><div >d2</div></div>", wt)
-}
-
-func TestIsNamedParamsSC(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/bynameorposition.html", `{{ with .Get "id" }}Named: {{ . }}{{ else }}Pos: {{ .Get 0 }}{{ end }}`)
- tem.AddTemplate("_internal/shortcodes/ifnamedparams.html", `<div id="{{ if .IsNamedParams }}{{ .Get "id" }}{{ else }}{{ .Get 0 }}{{end}}">`)
- return nil
- }
- CheckShortCodeMatch(t, `{{< ifnamedparams id="name" >}}`, `<div id="name">`, wt)
- CheckShortCodeMatch(t, `{{< ifnamedparams position >}}`, `<div id="position">`, wt)
- CheckShortCodeMatch(t, `{{< bynameorposition id="name" >}}`, `Named: name`, wt)
- CheckShortCodeMatch(t, `{{< bynameorposition position >}}`, `Pos: position`, wt)
-}
-
-func TestInnerSC(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/inside.html", `<div{{with .Get "class"}} class="{{.}}"{{end}}>{{ .Inner }}</div>`)
- return nil
- }
- CheckShortCodeMatch(t, `{{< inside class="aspen" >}}`, `<div class="aspen"></div>`, wt)
- CheckShortCodeMatch(t, `{{< inside class="aspen" >}}More Here{{< /inside >}}`, "<div class=\"aspen\">More Here</div>", wt)
- CheckShortCodeMatch(t, `{{< inside >}}More Here{{< /inside >}}`, "<div>More Here</div>", wt)
-}
-
-func TestInnerSCWithMarkdown(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- // Note: In Hugo 0.55 we made it so any outer {{%'s inner content was rendered as part of the surrounding
- // markup. This solved lots of problems, but it also meant that this test had to be adjusted.
- tem.AddTemplate("_internal/shortcodes/wrapper.html", `<div{{with .Get "class"}} class="{{.}}"{{end}}>{{ .Inner }}</div>`)
- tem.AddTemplate("_internal/shortcodes/inside.html", `{{ .Inner }}`)
- return nil
- }
- CheckShortCodeMatch(t, `{{< wrapper >}}{{% inside %}}
-# More Here
-
-[link](http://spf13.com) and text
-
-{{% /inside %}}{{< /wrapper >}}`, "<div><h1 id=\"more-here\">More Here</h1>\n\n<p><a href=\"http://spf13.com\">link</a> and text</p>\n</div>", wt)
-}
-
-func TestEmbeddedSC(t *testing.T) {
- t.Parallel()
- CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" %}}`, "<figure class=\"bananas orange\"><img src=\"/found/here\"/>\n</figure>", nil)
- CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" caption="This is a caption" %}}`, "<figure class=\"bananas orange\"><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) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/scn1.html", `<div>Outer, inner is {{ .Inner }}</div>`)
- tem.AddTemplate("_internal/shortcodes/scn2.html", `<div>SC2</div>`)
- return nil
- }
- CheckShortCodeMatch(t, `{{% scn1 %}}{{% scn2 %}}{{% /scn1 %}}`, "<div>Outer, inner is <div>SC2</div></div>", wt)
-
- CheckShortCodeMatch(t, `{{< scn1 >}}{{% scn2 %}}{{< /scn1 >}}`, "<div>Outer, inner is <div>SC2</div></div>", wt)
-}
-
-func TestNestedComplexSC(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/row.html", `-row-{{ .Inner}}-rowStop-`)
- tem.AddTemplate("_internal/shortcodes/column.html", `-col-{{.Inner }}-colStop-`)
- tem.AddTemplate("_internal/shortcodes/aside.html", `-aside-{{ .Inner }}-asideStop-`)
- return nil
- }
- CheckShortCodeMatch(t, `{{< row >}}1-s{{% column %}}2-**s**{{< aside >}}3-**s**{{< /aside >}}4-s{{% /column %}}5-s{{< /row >}}6-s`,
- "-row-1-s-col-2-<strong>s</strong>-aside-3-<strong>s</strong>-asideStop-4-s-colStop-5-s-rowStop-6-s", wt)
-
- // turn around the markup flag
- CheckShortCodeMatch(t, `{{% row %}}1-s{{< column >}}2-**s**{{% aside %}}3-**s**{{% /aside %}}4-s{{< /column >}}5-s{{% /row %}}6-s`,
- "-row-1-s-col-2-<strong>s</strong>-aside-3-<strong>s</strong>-asideStop-4-s-colStop-5-s-rowStop-6-s", wt)
-}
-
-func TestParentShortcode(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/r1.html", `1: {{ .Get "pr1" }} {{ .Inner }}`)
- tem.AddTemplate("_internal/shortcodes/r2.html", `2: {{ .Parent.Get "pr1" }}{{ .Get "pr2" }} {{ .Inner }}`)
- tem.AddTemplate("_internal/shortcodes/r3.html", `3: {{ .Parent.Parent.Get "pr1" }}{{ .Parent.Get "pr2" }}{{ .Get "pr3" }} {{ .Inner }}`)
- return nil
- }
- CheckShortCodeMatch(t, `{{< r1 pr1="p1" >}}1: {{< r2 pr2="p2" >}}2: {{< r3 pr3="p3" >}}{{< /r3 >}}{{< /r2 >}}{{< /r1 >}}`,
- "1: p1 1: 2: p1p2 2: 3: p1p2p3 ", wt)
-}
-
-func TestFigureOnlySrc(t *testing.T) {
- t.Parallel()
- CheckShortCodeMatch(t, `{{< figure src="/found/here" >}}`, "<figure><img src=\"/found/here\"/>\n</figure>", nil)
-}
-
-func TestFigureCaptionAttrWithMarkdown(t *testing.T) {
- t.Parallel()
- CheckShortCodeMatch(t, `{{< figure src="/found/here" caption="Something **bold** _italic_" >}}`, "<figure><img src=\"/found/here\"\n alt=\"Something bold italic\"/><figcaption>\n <p>Something <strong>bold</strong> <em>italic</em></p>\n </figcaption>\n</figure>", nil)
- CheckShortCodeMatch(t, `{{< figure src="/found/here" attr="Something **bold** _italic_" >}}`, "<figure><img src=\"/found/here\"/><figcaption>\n <p>Something <strong>bold</strong> <em>italic</em></p>\n </figcaption>\n</figure>", nil)
-}
-
-func TestFigureImgWidth(t *testing.T) {
- t.Parallel()
- CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="100px" %}}`, "<figure class=\"bananas orange\"><img src=\"/found/here\"\n alt=\"apple\" width=\"100px\"/>\n</figure>", nil)
-}
-
-func TestFigureImgHeight(t *testing.T) {
- t.Parallel()
- CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" height="100px" %}}`, "<figure class=\"bananas orange\"><img src=\"/found/here\"\n alt=\"apple\" height=\"100px\"/>\n</figure>", nil)
-}
-
-func TestFigureImgWidthAndHeight(t *testing.T) {
- t.Parallel()
- CheckShortCodeMatch(t, `{{% figure src="/found/here" class="bananas orange" alt="apple" width="50" height="100" %}}`, "<figure class=\"bananas orange\"><img src=\"/found/here\"\n alt=\"apple\" width=\"50\" height=\"100\"/>\n</figure>", nil)
-}
-
-func TestFigureLinkNoTarget(t *testing.T) {
- t.Parallel()
- CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" >}}`, "<figure><a href=\"/jump/here/on/clicking\"><img src=\"/found/here\"/></a>\n</figure>", nil)
-}
-
-func TestFigureLinkWithTarget(t *testing.T) {
- t.Parallel()
- CheckShortCodeMatch(t, `{{< figure src="/found/here" link="/jump/here/on/clicking" target="_self" >}}`, "<figure><a href=\"/jump/here/on/clicking\" target=\"_self\"><img src=\"/found/here\"/></a>\n</figure>", nil)
-}
-
-func TestFigureLinkWithTargetAndRel(t *testing.T) {
- t.Parallel()
- 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\"><img src=\"/found/here\"/></a>\n</figure>", nil)
-}
-
-// #1642
-func TestShortcodeWrappedInPIssue(t *testing.T) {
- t.Parallel()
- wt := func(tem tpl.TemplateManager) error {
- tem.AddTemplate("_internal/shortcodes/bug.html", `xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx`)
- return nil
- }
- CheckShortCodeMatch(t, `
-{{< bug >}}
-
-{{< bug >}}
-`, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n\nxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", wt)
-}
-
-// #6866
-func TestShortcodeIncomplete(t *testing.T) {
- t.Parallel()
- CheckShortCodeMatchAndError(t, `{{< >}}`, ".*shortcode has no name.*", nil, true)
-}
-
func TestExtractShortcodes(t *testing.T) {
b := newTestSitesBuilder(t).WithSimpleConfigFile()
@@ -368,13 +49,6 @@ title: "Shortcodes Galore!"
s := b.H.Sites[0]
- /*errCheck := func(s string) func(name string, assert *require.Assertions, shortcode *shortcode, err error) {
- return func(name string, assert *require.Assertions, shortcode *shortcode, err error) {
- c.Assert(err, name, qt.Not(qt.IsNil))
- c.Assert(err.Error(), name, qt.Equals, s)
- }
- }*/
-
// Make it more regexp friendly
strReplacer := strings.NewReplacer("[", "{", "]", "}")
@@ -451,198 +125,6 @@ title: "Shortcodes Galore!"
}
}
-func TestShortcodesInSite(t *testing.T) {
- baseURL := "http://foo/bar"
-
- tests := []struct {
- contentPath string
- content string
- outFile string
- expected any
- }{
- {
- "sect/doc1.md", `a{{< b >}}c`,
- filepath.FromSlash("public/sect/doc1/index.html"), "<p>abc</p>\n",
- },
- // Issue #1642: Multiple shortcodes wrapped in P
- // Deliberately forced to pass even if they maybe shouldn't.
- {
- "sect/doc2.md", `a
-
-{{< b >}}
-{{< c >}}
-{{< d >}}
-
-e`,
- filepath.FromSlash("public/sect/doc2/index.html"),
- "<p>a</p>\n\n<p>b<br />\nc\nd</p>\n\n<p>e</p>\n",
- },
- {
- "sect/doc3.md", `a
-
-{{< b >}}
-{{< c >}}
-
-{{< d >}}
-
-e`,
- filepath.FromSlash("public/sect/doc3/index.html"),
- "<p>a</p>\n\n<p>b<br />\nc</p>\n\nd\n\n<p>e</p>\n",
- },
- {
- "sect/doc4.md", `a
-{{< b >}}
-{{< b >}}
-{{< b >}}
-{{< b >}}
-{{< b >}}
-
-
-
-
-
-
-
-
-
-
-`,
- filepath.FromSlash("public/sect/doc4/index.html"),
- "<p>a\nb\nb\nb\nb\nb</p>\n",
- },
- // #2192 #2209: Shortcodes in markdown headers
- {
- "sect/doc5.md", `# {{< b >}}
-## {{% c %}}`,
- filepath.FromSlash("public/sect/doc5/index.html"), `-hbhb">b</h1>`,
- },
- // #2223 pygments
- {
- "sect/doc6.md", "\n```bash\nb = {{< b >}} c = {{% c %}}\n```\n",
- filepath.FromSlash("public/sect/doc6/index.html"),
- `<span class="nv">b</span>`,
- },
- // #2249
- {
- "sect/doc7.ad", `_Shortcodes:_ *b: {{< b >}} c: {{% c %}}*`,
- filepath.FromSlash("public/sect/doc7/index.html"),
- "<div class=\"paragraph\">\n<p><em>Shortcodes:</em> <strong>b: b c: c</strong></p>\n</div>\n",
- },
- {
- "sect/doc8.rst", `**Shortcodes:** *b: {{< b >}} c: {{% c %}}*`,
- filepath.FromSlash("public/sect/doc8/index.html"),
- "<div class=\"document\">\n\n\n<p><strong>Shortcodes:</strong> <em>b: b c: c</em></p>\n</div>",
- },
-
- // Issue #1229: Menus not available in shortcode.
- {
- "sect/doc10.md", `---
-menu:
- main:
- identifier: 'parent'
-tags:
-- Menu
----
-**Menus:** {{< menu >}}`,
- filepath.FromSlash("public/sect/doc10/index.html"),
- "<p><strong>Menus:</strong> 1</p>\n",
- },
- // Issue #2323: Taxonomies not available in shortcode.
- {
- "sect/doc11.md", `---
-tags:
-- Bugs
-menu:
- main:
- parent: 'parent'
----
-**Tags:** {{< tags >}}`,
- filepath.FromSlash("public/sect/doc11/index.html"),
- "<p><strong>Tags:</strong> 2</p>\n",
- },
- {
- "sect/doc12.md", `---
-title: "Foo"
----
-
-{{% html-indented-v1 %}}`,
- "public/sect/doc12/index.html",
- "<h1>Hugo!</h1>",
- },
- }
-
- temp := tests[:0]
- for _, test := range tests {
- if strings.HasSuffix(test.contentPath, ".ad") && !asciidocext.Supports() {
- t.Log("Skip Asciidoc test case as no Asciidoc present.")
- continue
- } else if strings.HasSuffix(test.contentPath, ".rst") && !rst.Supports() {
- t.Log("Skip Rst test case as no rst2html present.")
- continue
- }
- temp = append(temp, test)
- }
- tests = temp
-
- sources := make([][2]string, len(tests))
-
- for i, test := range tests {
- sources[i] = [2]string{filepath.FromSlash(test.contentPath), test.content}
- }
-
- addTemplates := func(templ tpl.TemplateManager) error {
- templ.AddTemplate("_default/single.html", "{{.Content}} Word Count: {{ .WordCount }}")
-
- templ.AddTemplate("_internal/shortcodes/b.html", `b`)
- templ.AddTemplate("_internal/shortcodes/c.html", `c`)
- templ.AddTemplate("_internal/shortcodes/d.html", `d`)
- templ.AddTemplate("_internal/shortcodes/html-indented-v1.html", "{{ $_hugo_config := `{ \"version\": 1 }` }}"+`
- <h1>Hugo!</h1>
-`)
- templ.AddTemplate("_internal/shortcodes/menu.html", `{{ len (index .Page.Menus "main").Children }}`)
- templ.AddTemplate("_internal/shortcodes/tags.html", `{{ len .Page.Site.Taxonomies.tags }}`)
-
- return nil
- }
-
- cfg, fs := newTestCfg()
-
- cfg.Set("defaultContentLanguage", "en")
- cfg.Set("baseURL", baseURL)
- cfg.Set("uglyURLs", false)
- cfg.Set("verbose", true)
-
- cfg.Set("security", map[string]any{
- "exec": map[string]any{
- "allow": []string{"^python$", "^rst2html.*", "^asciidoctor$"},
- },
- })
-
- cfg.Set("markup.highlight.noClasses", false)
- cfg.Set("markup.highlight.codeFences", true)
- cfg.Set("markup", map[string]any{
- "defaultMarkdownHandler": "blackfriday", // TODO(bep)
- })
-
- writeSourcesToSource(t, "content", fs, sources...)
-
- s := buildSingleSite(t, deps.DepsCfg{WithTemplate: addTemplates, Fs: fs, Cfg: cfg}, BuildCfg{})
-
- for i, test := range tests {
- test := test
- t.Run(fmt.Sprintf("test=%d;contentPath=%s", i, test.contentPath), func(t *testing.T) {
- t.Parallel()
-
- th := newTestHelper(s.Cfg, s.Fs, t)
-
- expected := cast.ToStringSlice(test.expected)
-
- th.assertFileContent(filepath.FromSlash(test.outFile), expected...)
- })
-
- }
-}
-
func TestShortcodeMultipleOutputFormats(t *testing.T) {
t.Parallel()
@@ -1272,24 +754,15 @@ Get: {{ printf "%v (%T)" $b1 $b1 | safeHTML }}
}
func TestShortcodeRef(t *testing.T) {
- for _, plainIDAnchors := range []bool{false, true} {
- plainIDAnchors := plainIDAnchors
- t.Run(fmt.Sprintf("plainIDAnchors=%t", plainIDAnchors), func(t *testing.T) {
- t.Parallel()
+ t.Parallel()
- v := config.NewWithTestDefaults()
- v.Set("baseURL", "https://example.org")
- v.Set("blackfriday", map[string]any{
- "plainIDAnchors": plainIDAnchors,
- })
- v.Set("markup", map[string]any{
- "defaultMarkdownHandler": "blackfriday", // TODO(bep)
- })
+ v := config.NewWithTestDefaults()
+ v.Set("baseURL", "https://example.org")
- builder := newTestSitesBuilder(t).WithViper(v)
+ builder := newTestSitesBuilder(t).WithViper(v)
- for i := 1; i <= 2; i++ {
- builder.WithContent(fmt.Sprintf("page%d.md", i), `---
+ for i := 1; i <= 2; i++ {
+ builder.WithContent(fmt.Sprintf("page%d.md", i), `---
title: "Hugo Rocks!"
---
@@ -1305,33 +778,19 @@ title: "Hugo Rocks!"
`)
- }
+ }
- builder.Build(BuildCfg{})
+ builder.Build(BuildCfg{})
- if plainIDAnchors {
- builder.AssertFileContent("public/page2/index.html",
- `
+ builder.AssertFileContent("public/page2/index.html", `
<a href="/page1/#doc">Page 1 with anchor</a>
<a href="https://example.org/page2/">Page 2</a>
<a href="/page2/#doc">Page 2 with anchor</a></p>
<h2 id="doc">Doc</h2>
`,
- )
- } else {
- builder.AssertFileContent("public/page2/index.html",
- `
-<p><a href="https://example.org/page1/">Page 1</a>
-<a href="/page1/#doc:45ca767ba77bc1445a0acab74f80812f">Page 1 with anchor</a>
-<a href="https://example.org/page2/">Page 2</a>
-<a href="/page2/#doc:8e3cdf52fa21e33270c99433820e46bd">Page 2 with anchor</a></p>
-<h2 id="doc:8e3cdf52fa21e33270c99433820e46bd">Doc</h2>
-`,
- )
- }
- })
- }
+ )
+
}
// https://github.com/gohugoio/hugo/issues/6857