summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--hugolib/case_insensitive_test.go231
-rw-r--r--hugolib/config.go5
-rw-r--r--hugolib/hugo_sites_build_test.go63
-rw-r--r--hugolib/page.go4
-rw-r--r--hugolib/page__content.go2
-rw-r--r--hugolib/page__meta.go27
-rw-r--r--hugolib/page__per_output.go2
-rw-r--r--hugolib/page_test.go104
-rw-r--r--hugolib/shortcode.go4
-rw-r--r--hugolib/shortcode_test.go563
-rw-r--r--hugolib/site_test.go7
-rw-r--r--hugolib/testhelpers_test.go5
-rw-r--r--markup/blackfriday/anchors.go39
-rw-r--r--markup/blackfriday/blackfriday_config/config.go71
-rw-r--r--markup/blackfriday/convert.go233
-rw-r--r--markup/blackfriday/convert_test.go223
-rw-r--r--markup/blackfriday/renderer.go84
-rw-r--r--markup/converter/converter.go9
-rw-r--r--markup/markup.go6
-rw-r--r--markup/markup_config/config.go29
-rw-r--r--markup/markup_config/config_test.go34
-rw-r--r--markup/markup_test.go1
22 files changed, 71 insertions, 1675 deletions
diff --git a/hugolib/case_insensitive_test.go b/hugolib/case_insensitive_test.go
deleted file mode 100644
index 9aa88ab5b..000000000
--- a/hugolib/case_insensitive_test.go
+++ /dev/null
@@ -1,231 +0,0 @@
-// Copyright 2016 The Hugo Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package hugolib
-
-import (
- "path/filepath"
- "testing"
-
- "github.com/gohugoio/hugo/hugofs"
-
- qt "github.com/frankban/quicktest"
- "github.com/gohugoio/hugo/deps"
- "github.com/spf13/afero"
-)
-
-var (
- caseMixingSiteConfigTOML = `
-Title = "In an Insensitive Mood"
-DefaultContentLanguage = "nn"
-defaultContentLanguageInSubdir = true
-
-[Blackfriday]
-AngledQuotes = true
-HrefTargetBlank = true
-
-[Params]
-Search = true
-Color = "green"
-mood = "Happy"
-[Params.Colors]
-Blue = "blue"
-Yellow = "yellow"
-
-[Languages]
-[Languages.nn]
-title = "Nynorsk title"
-languageName = "Nynorsk"
-weight = 1
-
-[Languages.en]
-TITLE = "English title"
-LanguageName = "English"
-Mood = "Thoughtful"
-Weight = 2
-COLOR = "Pink"
-[Languages.en.blackfriday]
-angledQuotes = false
-hrefTargetBlank = false
-[Languages.en.Colors]
-BLUE = "blues"
-Yellow = "golden"
-`
- caseMixingPage1En = `
----
-TITLE: Page1 En Translation
-BlackFriday:
- AngledQuotes: false
-Color: "black"
-Search: true
-mooD: "sad and lonely"
-ColorS:
- Blue: "bluesy"
- Yellow: "sunny"
----
-# "Hi"
-{{< shortcode >}}
-`
-
- caseMixingPage1 = `
----
-titLe: Side 1
-blackFriday:
- angledQuotes: true
-color: "red"
-search: false
-MooD: "sad"
-COLORS:
- blue: "heavenly"
- yelloW: "Sunny"
----
-# "Hi"
-{{< shortcode >}}
-`
-
- caseMixingPage2 = `
----
-TITLE: Page2 Title
-BlackFriday:
- AngledQuotes: false
-Color: "black"
-search: true
-MooD: "moody"
-ColorS:
- Blue: "sky"
- YELLOW: "flower"
----
-# Hi
-{{< shortcode >}}
-`
-)
-
-func caseMixingTestsWriteCommonSources(t *testing.T, fs afero.Fs) {
- writeToFs(t, fs, filepath.Join("content", "sect1", "page1.md"), caseMixingPage1)
- writeToFs(t, fs, filepath.Join("content", "sect2", "page2.md"), caseMixingPage2)
- writeToFs(t, fs, filepath.Join("content", "sect1", "page1.en.md"), caseMixingPage1En)
-
- writeToFs(t, fs, "layouts/shortcodes/shortcode.html", `
-Shortcode Page: {{ .Page.Params.COLOR }}|{{ .Page.Params.Colors.Blue }}
-Shortcode Site: {{ .Page.Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
-`)
-
- writeToFs(t, fs, "layouts/partials/partial.html", `
-Partial Page: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }}
-Partial Site: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}
-Partial Site Global: {{ site.Params.COLOR }}|{{ site.Params.COLORS.YELLOW }}
-`)
-
- writeToFs(t, fs, "config.toml", caseMixingSiteConfigTOML)
-}
-
-func TestCaseInsensitiveConfigurationVariations(t *testing.T) {
- t.Parallel()
-
- c := qt.New(t)
-
- mm := afero.NewMemMapFs()
-
- caseMixingTestsWriteCommonSources(t, mm)
-
- cfg, _, err := LoadConfig(ConfigSourceDescriptor{Fs: mm, Filename: "config.toml"})
- c.Assert(err, qt.IsNil)
-
- fs := hugofs.NewFrom(mm, cfg)
-
- th := newTestHelper(cfg, fs, t)
-
- writeSource(t, fs, filepath.Join("layouts", "_default", "baseof.html"), `
-Block Page Colors: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }}
-{{ block "main" . }}default{{end}}`)
-
- writeSource(t, fs, filepath.Join("layouts", "sect2", "single.html"), `
-{{ define "main"}}
-Page Colors: {{ .Params.CoLOR }}|{{ .Params.Colors.Blue }}
-Site Colors: {{ .Site.Params.COlOR }}|{{ .Site.Params.COLORS.YELLOW }}
-{{ template "index-color" (dict "name" "Page" "params" .Params) }}
-{{ template "index-color" (dict "name" "Site" "params" .Site.Params) }}
-
-{{ .Content }}
-{{ partial "partial.html" . }}
-{{ end }}
-{{ define "index-color" }}
-{{ $yellow := index .params "COLoRS" "yELLOW" }}
-{{ $colors := index .params "COLoRS" }}
-{{ $yellow2 := index $colors "yEllow" }}
-index1|{{ .name }}: {{ $yellow }}|
-index2|{{ .name }}: {{ $yellow2 }}|
-{{ end }}
-`)
-
- writeSource(t, fs, filepath.Join("layouts", "_default", "single.html"), `
-Page Title: {{ .Title }}
-Site Title: {{ .Site.Title }}
-Site Lang Mood: {{ .Site.Language.Params.MOoD }}
-Page Colors: {{ .Params.COLOR }}|{{ .Params.Colors.Blue }}|{{ index .Params "ColOR" }}
-Site Colors: {{ .Site.Params.COLOR }}|{{ .Site.Params.COLORS.YELLOW }}|{{ index .Site.Params "ColOR" }}
-{{ $page2 := .Site.GetPage "/sect2/page2" }}
-{{ if $page2 }}
-Page2: {{ $page2.Params.ColoR }}
-{{ end }}
-{{ .Content }}
-{{ partial "partial.html" . }}
-`)
-
- sites, err := NewHugoSites(deps.DepsCfg{Fs: fs, Cfg: cfg})
- if err != nil {
- t.Fatalf("Failed to create sites: %s", err)
- }
-
- err = sites.Build(BuildCfg{})
-
- if err != nil {
- t.Fatalf("Failed to build sites: %s", err)
- }
-
- th.assertFileContent(filepath.Join("public", "nn", "sect1", "page1", "index.html"),
- "Page Colors: red|heavenly|red",
- "Site Colors: green|yellow|green",
- "Site Lang Mood: Happy",
- "Shortcode Page: red|heavenly",
- "Shortcode Site: green|yellow",
- "Partial Page: red|heavenly",
- "Partial Site: green|yellow",
- "Partial Site Global: green|yellow",
- "Page Title: Side 1",
- "Site Title: Nynorsk title",
- "Page2: black ",
- )
-
- th.assertFileContent(filepath.Join("public", "en", "sect1", "page1", "index.html"),
- "Site Colors: Pink|golden",
- "Page Colors: black|bluesy",
- "Site Lang Mood: Thoughtful",
- "Page Title: Page1 En Translation",
- "Site Title: English title",
- "&ldquo;Hi&rdquo;",
- )
-
- th.assertFileContent(filepath.Join("public", "nn", "sect2", "page2", "index.html"),
- "Page Colors: black|sky",
- "Site Colors: green|yellow",
- "Shortcode Page: black|sky",
- "Block Page Colors: black|sky",
- "Partial Page: black|sky",
- "Partial Site: green|yellow",
- "index1|Page: flower|",
- "index1|Site: yellow|",
- "index2|Page: flower|",
- "index2|Site: yellow|",
- )
-}
diff --git a/hugolib/config.go b/hugolib/config.go
index ef23086b5..8444d15d9 100644
--- a/hugolib/config.go
+++ b/hugolib/config.go
@@ -108,11 +108,6 @@ func LoadConfig(d ConfigSourceDescriptor, doWithConfig ...func(cfg config.Provid
}
}
- // Config deprecations.
- if l.cfg.GetString("markup.defaultMarkdownHandler") == "blackfriday" {
- helpers.Deprecated("markup.defaultMarkdownHandler=blackfriday", "See https://gohugo.io//content-management/formats/#list-of-content-formats", false)
- }
-
// Some settings are used before we're done collecting all settings,
// so apply OS environment both before and after.
if err := l.applyOsEnvOverrides(d.Environ); err != nil {
diff --git a/hugolib/hugo_sites_build_test.go b/hugolib/hugo_sites_build_test.go
index 4a629eedd..c31f94713 100644
--- a/hugolib/hugo_sites_build_test.go
+++ b/hugolib/hugo_sites_build_test.go
@@ -365,11 +365,6 @@ func doTestMultiSitesBuild(t *testing.T, configTemplate, configSuffix string) {
c.Assert(frTags["FRtag1"], qt.Not(qt.IsNil))
b.AssertFileContent("public/fr/plaques/FRtag1/index.html", "FRtag1|Bonjour|http://example.com/blog/fr/plaques/FRtag1/")
- // Check Blackfriday config
- c.Assert(strings.Contains(content(doc1fr), "&laquo;"), qt.Equals, true)
- c.Assert(strings.Contains(content(doc1en), "&laquo;"), qt.Equals, false)
- c.Assert(strings.Contains(content(doc1en), "&ldquo;"), qt.Equals, true)
-
// en and nn have custom site menus
c.Assert(len(frSite.Menus()), qt.Equals, 0)
c.Assert(len(enSite.Menus()), qt.Equals, 1)
@@ -796,39 +791,6 @@ categories: ["mycat"]
}
}
-// https://github.com/gohugoio/hugo/issues/5777
-func TestTableOfContentsInShortcodes(t *testing.T) {
- t.Parallel()
-
- b := newMultiSiteTestDefaultBuilder(t)
-
- b.WithTemplatesAdded("layouts/shortcodes/toc.html", tocShortcode)
- b.WithTemplatesAdded("layouts/shortcodes/wrapper.html", "{{ .Inner }}")
- b.WithContent("post/simple.en.md", tocPageSimple)
- b.WithContent("post/variants1.en.md", tocPageVariants1)
- b.WithContent("post/variants2.en.md", tocPageVariants2)
-
- b.WithContent("post/withSCInHeading.en.md", tocPageWithShortcodesInHeadings)
-
- b.CreateSites().Build(BuildCfg{})
-
- b.AssertFileContent("public/en/post/simple/index.html",
- tocPageSimpleExpected,
- // Make sure it is inserted twice
- `TOC1: <nav id="TableOfContents">`,
- `TOC2: <nav id="TableOfContents">`,
- )
-
- b.AssertFileContentFn("public/en/post/variants1/index.html", func(s string) bool {
- return strings.Count(s, "TableOfContents") == 4
- })
- b.AssertFileContentFn("public/en/post/variants2/index.html", func(s string) bool {
- return strings.Count(s, "TableOfContents") == 6
- })
-
- b.AssertFileContent("public/en/post/withSCInHeading/index.html", tocPageWithShortcodesInHeadingsExpected)
-}
-
var tocShortcode = `
TOC1: {{ .Page.TableOfContents }}
@@ -970,12 +932,6 @@ enableRobotsTXT = true
[permalinks]
other = "/somewhere/else/:filename"
-# TODO(bep)
-[markup]
- defaultMarkdownHandler = "blackfriday"
-[markup.blackfriday]
-angledQuotes = true
-
[Taxonomies]
tag = "tags"
@@ -984,8 +940,6 @@ tag = "tags"
weight = 10
title = "In English"
languageName = "English"
-[Languages.en.blackfriday]
-angledQuotes = false
[[Languages.en.menu.main]]
url = "/"
name = "Home"
@@ -1031,12 +985,6 @@ enableRobotsTXT: true
permalinks:
other: "/somewhere/else/:filename"
-# TODO(bep)
-markup:
- defaultMarkdownHandler: blackfriday
- blackFriday:
- angledQuotes: true
-
Taxonomies:
tag: "tags"
@@ -1045,8 +993,6 @@ Languages:
weight: 10
title: "In English"
languageName: "English"
- blackfriday:
- angledQuotes: false
menu:
main:
- url: "/"
@@ -1092,12 +1038,6 @@ var multiSiteJSONConfigTemplate = `
"permalinks": {
"other": "/somewhere/else/:filename"
},
- "markup": {
- "defaultMarkdownHandler": "blackfriday",
- "blackfriday": {
- "angledQuotes": true
- }
- },
"Taxonomies": {
"tag": "tags"
},
@@ -1106,9 +1046,6 @@ var multiSiteJSONConfigTemplate = `
"weight": 10,
"title": "In English",
"languageName": "English",
- "blackfriday": {
- "angledQuotes": false
- },
"menu": {
"main": [
{
diff --git a/hugolib/page.go b/hugolib/page.go
index 19d969532..8bf13e320 100644
--- a/hugolib/page.go
+++ b/hugolib/page.go
@@ -600,7 +600,7 @@ func (p *pageState) getContentConverter() converter.Converter {
// Only used for shortcode inner content.
markup = "markdown"
}
- p.m.contentConverter, err = p.m.newContentConverter(p, markup, p.m.renderingConfigOverrides)
+ p.m.contentConverter, err = p.m.newContentConverter(p, markup)
})
if err != nil {
@@ -698,7 +698,7 @@ Loop:
p.source.hasSummaryDivider = true
if meta.markup != "html" {
- // The content will be rendered by Blackfriday or similar,
+ // The content will be rendered by Goldmark or similar,
// and we need to track the summary.
rn.AddReplacement(internalSummaryDividerPre, it)
}
diff --git a/hugolib/page__content.go b/hugolib/page__content.go
index 52389c472..f6f4564eb 100644
--- a/hugolib/page__content.go
+++ b/hugolib/page__content.go
@@ -38,7 +38,7 @@ type pageContent struct {
source rawPageContent
}
-// returns the content to be processed by Blackfriday or similar.
+// returns the content to be processed by Goldmark or similar.
func (p pageContent) contentToRender(renderedShortcodes map[string]string) []byte {
source := p.source.parsed.Input()
diff --git a/hugolib/page__meta.go b/hugolib/page__meta.go
index 1c8748869..daf989f42 100644
--- a/hugolib/page__meta.go
+++ b/hugolib/page__meta.go
@@ -120,9 +120,8 @@ type pageMeta struct {
s *Site
- renderingConfigOverrides map[string]any
- contentConverterInit sync.Once
- contentConverter converter.Converter
+ contentConverterInit sync.Once
+ contentConverter converter.Converter
}
func (p *pageMeta) Aliases() []string {
@@ -744,21 +743,10 @@ func (p *pageMeta) applyDefaultValues(n *contentNode) error {
}
}
- if !p.f.IsZero() {
- var renderingConfigOverrides map[string]any
- bfParam := getParamToLower(p, "blackfriday")
- if bfParam != nil {
- renderingConfigOverrides = maps.ToStringMap(bfParam)
- }
-
- p.renderingConfigOverrides = renderingConfigOverrides
-
- }
-
return nil
}
-func (p *pageMeta) newContentConverter(ps *pageState, markup string, renderingConfigOverrides map[string]any) (converter.Converter, error) {
+func (p *pageMeta) newContentConverter(ps *pageState, markup string) (converter.Converter, error) {
if ps == nil {
panic("no Page provided")
}
@@ -780,11 +768,10 @@ func (p *pageMeta) newContentConverter(ps *pageState, markup string, renderingCo
cpp, err := cp.New(
converter.DocumentContext{
- Document: newPageForRenderHook(ps),
- DocumentID: id,
- DocumentName: path,
- Filename: filename,
- ConfigOverrides: renderingConfigOverrides,
+ Document: newPageForRenderHook(ps),
+ DocumentID: id,
+ DocumentName: path,
+ Filename: filename,
},
)
if err != nil {
diff --git a/hugolib/page__per_output.go b/hugolib/page__per_output.go
index 59299b709..3d0c6ad1d 100644
--- a/hugolib/page__per_output.go
+++ b/hugolib/page__per_output.go
@@ -375,7 +375,7 @@ func (p *pageContentOutput) RenderString(args ...any) (template.HTML, error) {
if opts.Markup != "" && opts.Markup != p.p.m.markup {
var err error
// TODO(bep) consider cache
- conv, err = p.p.m.newContentConverter(p.p, opts.Markup, nil)
+ conv, err = p.p.m.newContentConverter(p.p, opts.Markup)
if err != nil {
return "", p.p.wrapError(err)
}
diff --git a/hugolib/page_test.go b/hugolib/page_test.go
index e5f8840a6..1d9e3e348 100644
--- a/hugolib/page_test.go
+++ b/hugolib/page_test.go
@@ -240,16 +240,6 @@ the cylinder and strike me down. ## BB
"You're a great Granser," he cried delightedly, "always making believe them little marks mean something."
`
- simplePageWithAdditionalExtension = `+++
-[blackfriday]
- extensions = ["hardLineBreak"]
-+++
-first line.
-second line.
-
-fourth line.
-`
-
simplePageWithURL = `---
title: Simple
url: simple/url/
@@ -694,26 +684,6 @@ func TestPageWithShortCodeInSummary(t *testing.T) {
testAllMarkdownEnginesForPages(t, assertFunc, nil, simplePageWithShortcodeInSummary)
}
-func TestPageWithAdditionalExtension(t *testing.T) {
- t.Parallel()
- cfg, fs := newTestCfg()
- cfg.Set("markup", map[string]any{
- "defaultMarkdownHandler": "blackfriday", // TODO(bep)
- })
-
- c := qt.New(t)
-
- writeSource(t, fs, filepath.Join("content", "simple.md"), simplePageWithAdditionalExtension)
-
- s := buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{SkipRender: true})
-
- c.Assert(len(s.RegularPages()), qt.Equals, 1)
-
- p := s.RegularPages()[0]
-
- checkPageContent(t, p, "<p>first line.<br />\nsecond line.</p>\n\n<p>fourth line.</p>\n")
-}
-
func TestTableOfContents(t *testing.T) {
cfg, fs := newTestCfg()
c := qt.New(t)
@@ -1373,7 +1343,7 @@ title: "HTML Content"
---
`
b.WithContent("regular.html", frontmatter+`<h1>Hugo</h1>`)
- b.WithContent("noblackfridayforyou.html", frontmatter+`**Hugo!**`)
+ b.WithContent("nomarkdownforyou.html", frontmatter+`**Hugo!**`)
b.WithContent("manualsummary.html", frontmatter+`
<p>This is summary</p>
<!--more-->
@@ -1387,8 +1357,8 @@ title: "HTML Content"
"Summary: Hugo|Truncated: false")
b.AssertFileContent(
- "public/noblackfridayforyou/index.html",
- "Permalink: http://example.com/noblackfridayforyou/|**Hugo!**|",
+ "public/nomarkdownforyou/index.html",
+ "Permalink: http://example.com/nomarkdownforyou/|**Hugo!**|",
)
// https://github.com/gohugoio/hugo/issues/5723
@@ -2011,74 +1981,6 @@ Link with URL as text
`)
}
-func TestBlackfridayDefault(t *testing.T) {
- t.Parallel()
-
- b := newTestSitesBuilder(t).WithConfigFile("toml", `
-baseURL = "https://example.org"
-
-[markup]
-defaultMarkdownHandler="blackfriday"
-[markup.highlight]
-noClasses=false
-[markup.goldmark]
-[markup.goldmark.renderer]
-unsafe=true
-
-
-`)
- // Use the new attribute syntax to make sure it's not Goldmark.
- b.WithTemplatesAdded("_default/single.html", `
-Title: {{ .Title }}
-Content: {{ .Content }}
-
-`, "shortcodes/s.html", `## Code
-{{ .Inner }}
-`)
-
- content := `
-+++
-title = "A Page!"
-+++
-
-
-## Code Fense in Shortcode
-
-{{% s %}}
-S:
-{{% s %}}
-$$$bash {hl_lines=[1]}
-SHORT
-$$$
-{{% /s %}}
-{{% /s %}}
-
-## Code Fence
-
-$$$bash {hl_lines=[1]}
-MARKDOWN
-$$$
-
-`
- content = strings.ReplaceAll(content, "$$$", "```")
-
- for i, ext := range []string{"md", "html"} {
- b.WithContent(fmt.Sprintf("page%d.%s", i+1, ext), content)
- }
-
- b.Build(BuildCfg{})
-
- // Blackfriday does not support this extended attribute syntax.
- b.AssertFileContent("public/page1/index.html",
- `<pre tabindex="0"><code class="language-bash {hl_lines=[1]}" data-lang="bash {hl_lines=[1]}">SHORT</code></pre>`,
- `<pre tabindex="0"><code class="language-bash {hl_lines=[1]}" data-lang="bash {hl_lines=[1]}">MARKDOWN`,
- )
-
- b.AssertFileContent("public/page2/index.html",
- `<pre tabindex="0"><code class="language-bash {hl_lines=[1]}" data-lang="bash {hl_lines=[1]}">SHORT`,
- )
-}
-
func TestPageCaseIssues(t *testing.T) {
t.Parallel()
diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go
index 45d5f1ca8..e718d861a 100644
--- a/hugolib/shortcode.go
+++ b/hugolib/shortcode.go
@@ -174,7 +174,7 @@ type shortcode struct {
templs []tpl.Template // All output formats
// If set, the rendered shortcode is sent as part of the surrounding content
- // to Blackfriday and similar.
+ // to Goldmark and similar.
// Before Hug0 0.55 we didn't send any shortcode output to the markup
// renderer, and this flag told Hugo to process the {{ .Inner }} content
// separately.
@@ -182,7 +182,7 @@ type shortcode struct {
// {{ $_hugo_config := `{ "version": 1 }`}}
doMarkup bool
- // the placeholder in the source when passed to Blackfriday etc.
+ // the placeholder in the source when passed to Goldmark etc.
// This also identifies the rendered shortcode.
placeholder string
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</s