mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
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
This commit is contained in:
parent
3b478f50b7
commit
0f8dc47037
22 changed files with 71 additions and 1675 deletions
|
@ -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",
|
||||
"“Hi”",
|
||||
)
|
||||
|
||||
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|",
|
||||
)
|
||||
}
|
|
@ -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 {
|
||||
|
|
|
@ -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), "«"), qt.Equals, true)
|
||||
c.Assert(strings.Contains(content(doc1en), "«"), qt.Equals, false)
|
||||
c.Assert(strings.Contains(content(doc1en), "“"), 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": [
|
||||
{
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -238,16 +238,6 @@ the cylinder and strike me down. ## BB
|
|||
### BBB
|
||||
|
||||
"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 = `---
|
||||
|
@ -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()
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -287,11 +287,6 @@ func doTestShouldAlwaysHaveUglyURLs(t *testing.T, uglyURLs bool) {
|
|||
|
||||
cfg.Set("verbose", true)
|
||||
cfg.Set("baseURL", "http://auth/bub")
|
||||
cfg.Set("blackfriday",
|
||||
map[string]any{
|
||||
"plainIDAnchors": true,
|
||||
})
|
||||
|
||||
cfg.Set("uglyURLs", uglyURLs)
|
||||
|
||||
sources := [][2]string{
|
||||
|
@ -887,8 +882,6 @@ func setupLinkingMockSite(t *testing.T) *Site {
|
|||
})
|
||||
cfg.Set("pluralizeListTitles", false)
|
||||
cfg.Set("canonifyURLs", false)
|
||||
cfg.Set("blackfriday",
|
||||
map[string]any{})
|
||||
writeSourcesToSource(t, "content", fs, sources...)
|
||||
return buildSingleSite(t, deps.DepsCfg{Fs: fs, Cfg: cfg}, BuildCfg{})
|
||||
}
|
||||
|
|
|
@ -300,9 +300,6 @@ defaultContentLanguageInSubdir = true
|
|||
[permalinks]
|
||||
other = "/somewhere/else/:filename"
|
||||
|
||||
[blackfriday]
|
||||
angledQuotes = true
|
||||
|
||||
[Taxonomies]
|
||||
tag = "tags"
|
||||
|
||||
|
@ -311,8 +308,6 @@ tag = "tags"
|
|||
weight = 10
|
||||
title = "In English"
|
||||
languageName = "English"
|
||||
[Languages.en.blackfriday]
|
||||
angledQuotes = false
|
||||
[[Languages.en.menu.main]]
|
||||
url = "/"
|
||||
name = "Home"
|
||||
|
|
39
markup/blackfriday/anchors.go
Normal file
39
markup/blackfriday/anchors.go
Normal file
|
@ -0,0 +1,39 @@
|
|||
// Copyright 2022 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 blackfriday holds some copmpability functions for the old Blackfriday v1 Markdown engine.
|
||||
package blackfriday
|
||||
|
||||
import "unicode"
|
||||
|
||||
// SanitizedAnchorName is how Blackfriday sanitizes anchor names.
|
||||
// Implementation borrowed from https://github.com/russross/blackfriday/blob/a477dd1646916742841ed20379f941cfa6c5bb6f/block.go#L1464
|
||||
// Note that Hugo removed its Blackfriday support in v0.100.0, but you can still use this strategy for
|
||||
// auto ID generation.
|
||||
func SanitizedAnchorName(text string) string {
|
||||
var anchorName []rune
|
||||
futureDash := false
|
||||
for _, r := range text {
|
||||
switch {
|
||||
case unicode.IsLetter(r) || unicode.IsNumber(r):
|
||||
if futureDash && len(anchorName) > 0 {
|
||||
anchorName = append(anchorName, '-')
|
||||
}
|
||||
futureDash = false
|
||||
anchorName = append(anchorName, unicode.ToLower(r))
|
||||
default:
|
||||
futureDash = true
|
||||
}
|
||||
}
|
||||
return string(anchorName)
|
||||
}
|
|
@ -1,71 +0,0 @@
|
|||
// Copyright 2019 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 helpers implements general utility functions that work with
|
||||
// and on content. The helper functions defined here lay down the
|
||||
// foundation of how Hugo works with files and filepaths, and perform
|
||||
// string operations on content.
|
||||
|
||||
package blackfriday_config
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
// Default holds the default BlackFriday config.
|
||||
// Do not change!
|
||||
var Default = Config{
|
||||
Smartypants: true,
|
||||
AngledQuotes: false,
|
||||
SmartypantsQuotesNBSP: false,
|
||||
Fractions: true,
|
||||
HrefTargetBlank: false,
|
||||
NofollowLinks: false,
|
||||
NoreferrerLinks: false,
|
||||
SmartDashes: true,
|
||||
LatexDashes: true,
|
||||
PlainIDAnchors: true,
|
||||
TaskLists: true,
|
||||
SkipHTML: false,
|
||||
}
|
||||
|
||||
// Config holds configuration values for BlackFriday rendering.
|
||||
// It is kept here because it's used in several packages.
|
||||
type Config struct {
|
||||
Smartypants bool
|
||||
SmartypantsQuotesNBSP bool
|
||||
AngledQuotes bool
|
||||
Fractions bool
|
||||
HrefTargetBlank bool
|
||||
NofollowLinks bool
|
||||
NoreferrerLinks bool
|
||||
SmartDashes bool
|
||||
LatexDashes bool
|
||||
TaskLists bool
|
||||
PlainIDAnchors bool
|
||||
Extensions []string
|
||||
ExtensionsMask []string
|
||||
SkipHTML bool
|
||||
|
||||
FootnoteAnchorPrefix string
|
||||
FootnoteReturnLinkContents string
|
||||
}
|
||||
|
||||
func UpdateConfig(b Config, m map[string]any) (Config, error) {
|
||||
if err := mapstructure.Decode(m, &b); err != nil {
|
||||
return b, fmt.Errorf("failed to decode rendering config: %w", err)
|
||||
}
|
||||
return b, nil
|
||||
}
|
|
@ -1,233 +0,0 @@
|
|||
// Copyright 2019 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 blackfriday converts Markdown to HTML using Blackfriday v1.
|
||||
package blackfriday
|
||||
|
||||
import (
|
||||
"unicode"
|
||||
|
||||
"github.com/gohugoio/hugo/identity"
|
||||
"github.com/gohugoio/hugo/markup/blackfriday/blackfriday_config"
|
||||
"github.com/gohugoio/hugo/markup/converter"
|
||||
"github.com/russross/blackfriday"
|
||||
)
|
||||
|
||||
// Provider is the package entry point.
|
||||
var Provider converter.ProviderProvider = provider{}
|
||||
|
||||
type provider struct {
|
||||
}
|
||||
|
||||
func (p provider) New(cfg converter.ProviderConfig) (converter.Provider, error) {
|
||||
defaultExtensions := getMarkdownExtensions(cfg.MarkupConfig.BlackFriday)
|
||||
|
||||
return converter.NewProvider("blackfriday", func(ctx converter.DocumentContext) (converter.Converter, error) {
|
||||
b := cfg.MarkupConfig.BlackFriday
|
||||
extensions := defaultExtensions
|
||||
|
||||
if ctx.ConfigOverrides != nil {
|
||||
var err error
|
||||
b, err = blackfriday_config.UpdateConfig(b, ctx.ConfigOverrides)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
extensions = getMarkdownExtensions(b)
|
||||
}
|
||||
|
||||
return &blackfridayConverter{
|
||||
ctx: ctx,
|
||||
bf: b,
|
||||
extensions: extensions,
|
||||
cfg: cfg,
|
||||
}, nil
|
||||
}), nil
|
||||
}
|
||||
|
||||
type blackfridayConverter struct {
|
||||
ctx converter.DocumentContext
|
||||
bf blackfriday_config.Config
|
||||
extensions int
|
||||
cfg converter.ProviderConfig
|
||||
}
|
||||
|
||||
func (c *blackfridayConverter) SanitizeAnchorName(s string) string {
|
||||
return SanitizedAnchorName(s)
|
||||
}
|
||||
|
||||
// SanitizedAnchorName is how Blackfriday sanitizes anchor names.
|
||||
// Implementation borrowed from https://github.com/russross/blackfriday/blob/a477dd1646916742841ed20379f941cfa6c5bb6f/block.go#L1464
|
||||
func SanitizedAnchorName(text string) string {
|
||||
var anchorName []rune
|
||||
futureDash := false
|
||||
for _, r := range text {
|
||||
switch {
|
||||
case unicode.IsLetter(r) || unicode.IsNumber(r):
|
||||
if futureDash && len(anchorName) > 0 {
|
||||
anchorName = append(anchorName, '-')
|
||||
}
|
||||
futureDash = false
|
||||
anchorName = append(anchorName, unicode.ToLower(r))
|
||||
default:
|
||||
futureDash = true
|
||||
}
|
||||
}
|
||||
return string(anchorName)
|
||||
}
|
||||
|
||||
func (c *blackfridayConverter) AnchorSuffix() string {
|
||||
if c.bf.PlainIDAnchors {
|
||||
return ""
|
||||
}
|
||||
return ":" + c.ctx.DocumentID
|
||||
}
|
||||
|
||||
func (c *blackfridayConverter) Convert(ctx converter.RenderContext) (converter.Result, error) {
|
||||
r := c.getHTMLRenderer(ctx.RenderTOC)
|
||||
|
||||
return converter.Bytes(blackfriday.Markdown(ctx.Src, r, c.extensions)), nil
|
||||
}
|
||||
|
||||
func (c *blackfridayConverter) Supports(feature identity.Identity) bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *blackfridayConverter) getHTMLRenderer(renderTOC bool) blackfriday.Renderer {
|
||||
flags := getFlags(renderTOC, c.bf)
|
||||
|
||||
documentID := c.ctx.DocumentID
|
||||
|
||||
renderParameters := blackfriday.HtmlRendererParameters{
|
||||
FootnoteAnchorPrefix: c.bf.FootnoteAnchorPrefix,
|
||||
FootnoteReturnLinkContents: c.bf.FootnoteReturnLinkContents,
|
||||
}
|
||||
|
||||
if documentID != "" && !c.bf.PlainIDAnchors {
|
||||
renderParameters.FootnoteAnchorPrefix = documentID + ":" + renderParameters.FootnoteAnchorPrefix
|
||||
renderParameters.HeaderIDSuffix = ":" + documentID
|
||||
}
|
||||
|
||||
return &hugoHTMLRenderer{
|
||||
c: c,
|
||||
Renderer: blackfriday.HtmlRendererWithParameters(flags, "", "", renderParameters),
|
||||
}
|
||||
}
|
||||
|
||||
func getFlags(renderTOC bool, cfg blackfriday_config.Config) int {
|
||||
var flags int
|
||||
|
||||
if renderTOC {
|
||||
flags = blackfriday.HTML_TOC
|
||||
}
|
||||
|
||||
flags |= blackfriday.HTML_USE_XHTML
|
||||
flags |= blackfriday.HTML_FOOTNOTE_RETURN_LINKS
|
||||
|
||||
if cfg.Smartypants {
|
||||
flags |= blackfriday.HTML_USE_SMARTYPANTS
|
||||
}
|
||||
|
||||
if cfg.SmartypantsQuotesNBSP {
|
||||
flags |= blackfriday.HTML_SMARTYPANTS_QUOTES_NBSP
|
||||
}
|
||||
|
||||
if cfg.AngledQuotes {
|
||||
flags |= blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES
|
||||
}
|
||||
|
||||
if cfg.Fractions {
|
||||
flags |= blackfriday.HTML_SMARTYPANTS_FRACTIONS
|
||||
}
|
||||
|
||||
if cfg.HrefTargetBlank {
|
||||
flags |= blackfriday.HTML_HREF_TARGET_BLANK
|
||||
}
|
||||
|
||||
if cfg.NofollowLinks {
|
||||
flags |= blackfriday.HTML_NOFOLLOW_LINKS
|
||||
}
|
||||
|
||||
if cfg.NoreferrerLinks {
|
||||
flags |= blackfriday.HTML_NOREFERRER_LINKS
|
||||
}
|
||||
|
||||
if cfg.SmartDashes {
|
||||
flags |= blackfriday.HTML_SMARTYPANTS_DASHES
|
||||
}
|
||||
|
||||
if cfg.LatexDashes {
|
||||
flags |= blackfriday.HTML_SMARTYPANTS_LATEX_DASHES
|
||||
}
|
||||
|
||||
if cfg.SkipHTML {
|
||||
flags |= blackfriday.HTML_SKIP_HTML
|
||||
}
|
||||
|
||||
return flags
|
||||
}
|
||||
|
||||
func getMarkdownExtensions(cfg blackfriday_config.Config) int {
|
||||
// Default Blackfriday common extensions
|
||||
commonExtensions := 0 |
|
||||
blackfriday.EXTENSION_NO_INTRA_EMPHASIS |
|
||||
blackfriday.EXTENSION_TABLES |
|
||||
blackfriday.EXTENSION_FENCED_CODE |
|
||||
blackfriday.EXTENSION_AUTOLINK |
|
||||
blackfriday.EXTENSION_STRIKETHROUGH |
|
||||
blackfriday.EXTENSION_SPACE_HEADERS |
|
||||
blackfriday.EXTENSION_HEADER_IDS |
|
||||
blackfriday.EXTENSION_BACKSLASH_LINE_BREAK |
|
||||
blackfriday.EXTENSION_DEFINITION_LISTS
|
||||
|
||||
// Extra Blackfriday extensions that Hugo enables by default
|
||||
flags := commonExtensions |
|
||||
blackfriday.EXTENSION_AUTO_HEADER_IDS |
|
||||
blackfriday.EXTENSION_FOOTNOTES
|
||||
|
||||
for _, extension := range cfg.Extensions {
|
||||
if flag, ok := blackfridayExtensionMap[extension]; ok {
|
||||
flags |= flag
|
||||
}
|
||||
}
|
||||
for _, extension := range cfg.ExtensionsMask {
|
||||
if flag, ok := blackfridayExtensionMap[extension]; ok {
|
||||
flags &= ^flag
|
||||
}
|
||||
}
|
||||
return flags
|
||||
}
|
||||
|
||||
var blackfridayExtensionMap = map[string]int{
|
||||
"noIntraEmphasis": blackfriday.EXTENSION_NO_INTRA_EMPHASIS,
|
||||
"tables": blackfriday.EXTENSION_TABLES,
|
||||
"fencedCode": blackfriday.EXTENSION_FENCED_CODE,
|
||||
"autolink": blackfriday.EXTENSION_AUTOLINK,
|
||||
"strikethrough": blackfriday.EXTENSION_STRIKETHROUGH,
|
||||
"laxHtmlBlocks": blackfriday.EXTENSION_LAX_HTML_BLOCKS,
|
||||
"spaceHeaders": blackfriday.EXTENSION_SPACE_HEADERS,
|
||||
"hardLineBreak": blackfriday.EXTENSION_HARD_LINE_BREAK,
|
||||
"tabSizeEight": blackfriday.EXTENSION_TAB_SIZE_EIGHT,
|
||||
"footnotes": blackfriday.EXTENSION_FOOTNOTES,
|
||||
"noEmptyLineBeforeBlock": blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK,
|
||||
"headerIds": blackfriday.EXTENSION_HEADER_IDS,
|
||||
"titleblock": blackfriday.EXTENSION_TITLEBLOCK,
|
||||
"autoHeaderIds": blackfriday.EXTENSION_AUTO_HEADER_IDS,
|
||||
"backslashLineBreak": blackfriday.EXTENSION_BACKSLASH_LINE_BREAK,
|
||||
"definitionLists": blackfriday.EXTENSION_DEFINITION_LISTS,
|
||||
"joinLines": blackfriday.EXTENSION_JOIN_LINES,
|
||||
}
|
||||
|
||||
var (
|
||||
_ converter.DocumentInfo = (*blackfridayConverter)(nil)
|
||||
_ converter.AnchorNameSanitizer = (*blackfridayConverter)(nil)
|
||||
)
|
|
@ -1,223 +0,0 @@
|
|||
// Copyright 2019 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 blackfriday
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/gohugoio/hugo/config"
|
||||
|
||||
"github.com/gohugoio/hugo/markup/converter"
|
||||
|
||||
qt "github.com/frankban/quicktest"
|
||||
"github.com/gohugoio/hugo/markup/blackfriday/blackfriday_config"
|
||||
"github.com/russross/blackfriday"
|
||||
)
|
||||
|
||||
func TestGetMarkdownExtensionsMasksAreRemovedFromExtensions(t *testing.T) {
|
||||
b := blackfriday_config.Default
|
||||
b.Extensions = []string{"headerId"}
|
||||
b.ExtensionsMask = []string{"noIntraEmphasis"}
|
||||
|
||||
actualFlags := getMarkdownExtensions(b)
|
||||
if actualFlags&blackfriday.EXTENSION_NO_INTRA_EMPHASIS == blackfriday.EXTENSION_NO_INTRA_EMPHASIS {
|
||||
t.Errorf("Masked out flag {%v} found amongst returned extensions.", blackfriday.EXTENSION_NO_INTRA_EMPHASIS)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMarkdownExtensionsByDefaultAllExtensionsAreEnabled(t *testing.T) {
|
||||
type data struct {
|
||||
testFlag int
|
||||
}
|
||||
|
||||
b := blackfriday_config.Default
|
||||
|
||||
b.Extensions = []string{""}
|
||||
b.ExtensionsMask = []string{""}
|
||||
allExtensions := []data{
|
||||
{blackfriday.EXTENSION_NO_INTRA_EMPHASIS},
|
||||
{blackfriday.EXTENSION_TABLES},
|
||||
{blackfriday.EXTENSION_FENCED_CODE},
|
||||
{blackfriday.EXTENSION_AUTOLINK},
|
||||
{blackfriday.EXTENSION_STRIKETHROUGH},
|
||||
// {blackfriday.EXTENSION_LAX_HTML_BLOCKS},
|
||||
{blackfriday.EXTENSION_SPACE_HEADERS},
|
||||
// {blackfriday.EXTENSION_HARD_LINE_BREAK},
|
||||
// {blackfriday.EXTENSION_TAB_SIZE_EIGHT},
|
||||
{blackfriday.EXTENSION_FOOTNOTES},
|
||||
// {blackfriday.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK},
|
||||
{blackfriday.EXTENSION_HEADER_IDS},
|
||||
// {blackfriday.EXTENSION_TITLEBLOCK},
|
||||
{blackfriday.EXTENSION_AUTO_HEADER_IDS},
|
||||
{blackfriday.EXTENSION_BACKSLASH_LINE_BREAK},
|
||||
{blackfriday.EXTENSION_DEFINITION_LISTS},
|
||||
}
|
||||
|
||||
actualFlags := getMarkdownExtensions(b)
|
||||
for _, e := range allExtensions {
|
||||
if actualFlags&e.testFlag != e.testFlag {
|
||||
t.Errorf("Flag %v was not found in the list of extensions.", e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetMarkdownExtensionsAddingFlagsThroughRenderingContext(t *testing.T) {
|
||||
b := blackfriday_config.Default
|
||||
|
||||
b.Extensions = []string{"definitionLists"}
|
||||
b.ExtensionsMask = []string{""}
|
||||
|
||||
actualFlags := getMarkdownExtensions(b)
|
||||
if actualFlags&blackfriday.EXTENSION_DEFINITION_LISTS != blackfriday.EXTENSION_DEFINITION_LISTS {
|
||||
t.Errorf("Masked out flag {%v} found amongst returned extensions.", blackfriday.EXTENSION_DEFINITION_LISTS)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetFlags(t *testing.T) {
|
||||
b := blackfriday_config.Default
|
||||
flags := getFlags(false, b)
|
||||
if flags&blackfriday.HTML_USE_XHTML != blackfriday.HTML_USE_XHTML {
|
||||
t.Errorf("Test flag: %d was not found amongs set flags:%d; Result: %d", blackfriday.HTML_USE_XHTML, flags, flags&blackfriday.HTML_USE_XHTML)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGetAllFlags(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
|
||||
b := blackfriday_config.Default
|
||||
|
||||
type data struct {
|
||||
testFlag int
|
||||
}
|
||||
|
||||
allFlags := []data{
|
||||
{blackfriday.HTML_USE_XHTML},
|
||||
{blackfriday.HTML_FOOTNOTE_RETURN_LINKS},
|
||||
{blackfriday.HTML_USE_SMARTYPANTS},
|
||||
{blackfriday.HTML_SMARTYPANTS_QUOTES_NBSP},
|
||||
{blackfriday.HTML_SMARTYPANTS_ANGLED_QUOTES},
|
||||
{blackfriday.HTML_SMARTYPANTS_FRACTIONS},
|
||||
{blackfriday.HTML_HREF_TARGET_BLANK},
|
||||
{blackfriday.HTML_NOFOLLOW_LINKS},
|
||||
{blackfriday.HTML_NOREFERRER_LINKS},
|
||||
{blackfriday.HTML_SMARTYPANTS_DASHES},
|
||||
{blackfriday.HTML_SMARTYPANTS_LATEX_DASHES},
|
||||
}
|
||||
|
||||
b.AngledQuotes = true
|
||||
b.Fractions = true
|
||||
b.HrefTargetBlank = true
|
||||
b.NofollowLinks = true
|
||||
b.NoreferrerLinks = true
|
||||
b.LatexDashes = true
|
||||
b.PlainIDAnchors = true
|
||||
b.SmartDashes = true
|
||||
b.Smartypants = true
|
||||
b.SmartypantsQuotesNBSP = true
|
||||
|
||||
actualFlags := getFlags(false, b)
|
||||
|
||||
var expectedFlags int
|
||||
// OR-ing flags together...
|
||||
for _, d := range allFlags {
|
||||
expectedFlags |= d.testFlag
|
||||
}
|
||||
|
||||
c.Assert(actualFlags, qt.Equals, expectedFlags)
|
||||
}
|
||||
|
||||
func TestConvert(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
p, err := Provider.New(converter.ProviderConfig{
|
||||
Cfg: config.New(),
|
||||
})
|
||||
c.Assert(err, qt.IsNil)
|
||||
conv, err := p.New(converter.DocumentContext{})
|
||||
c.Assert(err, qt.IsNil)
|
||||
b, err := conv.Convert(converter.RenderContext{Src: []byte("testContent")})
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(string(b.Bytes()), qt.Equals, "<p>testContent</p>\n")
|
||||
}
|
||||
|
||||
func TestGetHTMLRendererAnchors(t *testing.T) {
|
||||
c := qt.New(t)
|
||||
p, err := Provider.New(converter.ProviderConfig{
|
||||
Cfg: config.New(),
|
||||
})
|
||||
c.Assert(err, qt.IsNil)
|
||||
conv, err := p.New(converter.DocumentContext{
|
||||
DocumentID: "testid",
|
||||
ConfigOverrides: map[string]any{
|
||||
"plainIDAnchors": false,
|
||||
"footnotes": true,
|
||||
},
|
||||
})
|
||||
c.Assert(err, qt.IsNil)
|
||||
b, err := conv.Convert(converter.RenderContext{Src: []byte(`# Header
|
||||
|
||||
This is a footnote.[^1] And then some.
|
||||
|
||||
|
||||
[^1]: Footnote text.
|
||||
|
||||
`)})
|
||||
|
||||
c.Assert(err, qt.IsNil)
|
||||
s := string(b.Bytes())
|
||||
c.Assert(s, qt.Contains, "<h1 id=\"header:testid\">Header</h1>")
|
||||
c.Assert(s, qt.Contains, "This is a footnote.<sup class=\"footnote-ref\" id=\"fnref:testid:1\"><a href=\"#fn:testid:1\">1</a></sup>")
|
||||
c.Assert(s, qt.Contains, "<a class=\"footnote-return\" href=\"#fnref:testid:1\"><sup>[return]</sup></a>")
|
||||
}
|
||||
|
||||
// Tests borrowed from https://github.com/russross/blackfriday/blob/a925a152c144ea7de0f451eaf2f7db9e52fa005a/block_test.go#L1817
|
||||
func TestSanitizedAnchorName(t *testing.T) {
|
||||
tests := []struct {
|
||||
text string
|
||||
want string
|
||||
}{
|
||||
{
|
||||
text: "This is a header",
|
||||
want: "this-is-a-header",
|
||||
},
|
||||
{
|
||||
text: "This is also a header",
|
||||
want: "this-is-also-a-header",
|
||||
},
|
||||
{
|
||||
text: "main.go",
|
||||
want: "main-go",
|
||||
},
|
||||
{
|
||||
text: "Article 123",
|
||||
want: "article-123",
|
||||
},
|
||||
{
|
||||
text: "<- Let's try this, shall we?",
|
||||
want: "let-s-try-this-shall-we",
|
||||
},
|
||||
{
|
||||
text: " ",
|
||||
want: "",
|
||||
},
|
||||
{
|
||||
text: "Hello, 世界",
|
||||
want: "hello-世界",
|
||||
},
|
||||
}
|
||||
for _, test := range tests {
|
||||
if got := SanitizedAnchorName(test.text); got != test.want {
|
||||
t.Errorf("SanitizedAnchorName(%q):\ngot %q\nwant %q", test.text, got, test.want)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
// Copyright 2019 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 blackfriday
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"strings"
|
||||
|
||||
"github.com/russross/blackfriday"
|
||||
)
|
||||
|
||||
// hugoHTMLRenderer wraps a blackfriday.Renderer, typically a blackfriday.Html
|
||||
// adding some custom behaviour.
|
||||
type hugoHTMLRenderer struct {
|
||||
c *blackfridayConverter
|
||||
blackfriday.Renderer
|
||||
}
|
||||
|
||||
// BlockCode renders a given text as a block of code.
|
||||
// Chroma is used if it is setup to handle code fences.
|
||||
func (r *hugoHTMLRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string) {
|
||||
if r.c.cfg.MarkupConfig.Highlight.CodeFences {
|
||||
str := strings.Trim(string(text), "\n\r")
|
||||
highlighted, _ := r.c.cfg.Highlight(str, lang, "")
|
||||
out.WriteString(highlighted)
|
||||
} else {
|
||||
r.Renderer.BlockCode(out, text, lang)
|
||||
}
|
||||
}
|
||||
|
||||
// ListItem adds task list support to the Blackfriday renderer.
|
||||
func (r *hugoHTMLRenderer) ListItem(out *bytes.Buffer, text []byte, flags int) {
|
||||
if !r.c.bf.TaskLists {
|
||||
r.Renderer.ListItem(out, text, flags)
|
||||
return
|
||||
}
|
||||
|
||||
switch {
|
||||
case bytes.HasPrefix(text, []byte("[ ] ")):
|
||||
text = append([]byte(`<label><input type="checkbox" disabled class="task-list-item">`), text[3:]...)
|
||||
text = append(text, []byte(`</label>`)...)
|
||||
|
||||
case bytes.HasPrefix(text, []byte("[x] ")) || bytes.HasPrefix(text, []byte("[X] ")):
|
||||
text = append([]byte(`<label><input type="checkbox" checked disabled class="task-list-item">`), text[3:]...)
|
||||
text = append(text, []byte(`</label>`)...)
|
||||
}
|
||||
|
||||
r.Renderer.ListItem(out, text, flags)
|
||||
}
|
||||
|
||||
// List adds task list support to the Blackfriday renderer.
|
||||
func (r *hugoHTMLRenderer) List(out *bytes.Buffer, text func() bool, flags int) {
|
||||
if !r.c.bf.TaskLists {
|
||||
r.Renderer.List(out, text, flags)
|
||||
return
|
||||
}
|
||||
marker := out.Len()
|
||||
r.Renderer.List(out, text, flags)
|
||||
if out.Len() > marker {
|
||||
list := out.Bytes()[marker:]
|
||||
if bytes.Contains(list, []byte("task-list-item")) {
|
||||
// Find the index of the first >, it might be 3 or 4 depending on whether
|
||||
// there is a new line at the start, but this is safer than just hardcoding it.
|
||||
closingBracketIndex := bytes.Index(list, []byte(">"))
|
||||
// Rewrite the buffer from the marker
|
||||
out.Truncate(marker)
|
||||
// Safely assuming closingBracketIndex won't be -1 since there is a list
|
||||
// May be either dl, ul or ol
|
||||
list := append(list[:closingBracketIndex], append([]byte(` class="task-list"`), list[closingBracketIndex:]...)...)
|
||||
out.Write(list)
|
||||
}
|
||||
}
|
||||
}
|
|
@ -119,11 +119,10 @@ func (b Bytes) Bytes() []byte {
|
|||
|
||||
// DocumentContext holds contextual information about the document to convert.
|
||||
type DocumentContext struct {
|
||||
Document any // May be nil. Usually a page.Page
|
||||
DocumentID string
|
||||
DocumentName string
|
||||
Filename string
|
||||
ConfigOverrides map[string]any
|
||||
Document any // May be nil. Usually a page.Page
|
||||
DocumentID string
|
||||
DocumentName string
|
||||
Filename string
|
||||
}
|
||||
|
||||
// RenderContext holds contextual information about the content to render.
|
||||
|
|
|
@ -25,7 +25,6 @@ import (
|
|||
"github.com/gohugoio/hugo/markup/org"
|
||||
|
||||
"github.com/gohugoio/hugo/markup/asciidocext"
|
||||
"github.com/gohugoio/hugo/markup/blackfriday"
|
||||
"github.com/gohugoio/hugo/markup/converter"
|
||||
"github.com/gohugoio/hugo/markup/pandoc"
|
||||
"github.com/gohugoio/hugo/markup/rst"
|
||||
|
@ -66,9 +65,6 @@ func NewConverterProvider(cfg converter.ProviderConfig) (ConverterProvider, erro
|
|||
if err := add(goldmark.Provider); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := add(blackfriday.Provider); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if err := add(asciidocext.Provider, "ad", "adoc"); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
@ -96,7 +92,7 @@ type ConverterProvider interface {
|
|||
}
|
||||
|
||||
type converterRegistry struct {
|
||||
// Maps name (md, markdown, blackfriday etc.) to a converter provider.
|
||||
// Maps name (md, markdown, goldmark etc.) to a converter provider.
|
||||
// Note that this is also used for aliasing, so the same converter
|
||||
// may be registered multiple times.
|
||||
// All names are lower case.
|
||||
|
|
|
@ -18,7 +18,6 @@ import (
|
|||
"github.com/gohugoio/hugo/config"
|
||||
"github.com/gohugoio/hugo/docshelper"
|
||||
"github.com/gohugoio/hugo/markup/asciidocext/asciidocext_config"
|
||||
"github.com/gohugoio/hugo/markup/blackfriday/blackfriday_config"
|
||||
"github.com/gohugoio/hugo/markup/goldmark/goldmark_config"
|
||||
"github.com/gohugoio/hugo/markup/highlight"
|
||||
"github.com/gohugoio/hugo/markup/tableofcontents"
|
||||
|
@ -37,8 +36,6 @@ type Config struct {
|
|||
|
||||
// Content renderers
|
||||
Goldmark goldmark_config.Config
|
||||
BlackFriday blackfriday_config.Config
|
||||
|
||||
AsciidocExt asciidocext_config.Config
|
||||
}
|
||||
|
||||
|
@ -56,10 +53,6 @@ func Decode(cfg config.Provider) (conf Config, err error) {
|
|||
return
|
||||
}
|
||||
|
||||
if err = applyLegacyConfig(cfg, &conf); err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
if err = highlight.ApplyLegacyConfig(cfg, &conf.Highlight); err != nil {
|
||||
return
|
||||
}
|
||||
|
@ -83,26 +76,6 @@ func normalizeConfig(m map[string]any) {
|
|||
}
|
||||
}
|
||||
|
||||
func applyLegacyConfig(cfg config.Provider, conf *Config) error {
|
||||
if bm := cfg.GetStringMap("blackfriday"); bm != nil {
|
||||
// Legacy top level blackfriday config.
|
||||
err := mapstructure.WeakDecode(bm, &conf.BlackFriday)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
|
||||
if conf.BlackFriday.FootnoteAnchorPrefix == "" {
|
||||
conf.BlackFriday.FootnoteAnchorPrefix = cfg.GetString("footnoteAnchorPrefix")
|
||||
}
|
||||
|
||||
if conf.BlackFriday.FootnoteReturnLinkContents == "" {
|
||||
conf.BlackFriday.FootnoteReturnLinkContents = cfg.GetString("footnoteReturnLinkContents")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
var Default = Config{
|
||||
DefaultMarkdownHandler: "goldmark",
|
||||
|
||||
|
@ -110,8 +83,6 @@ var Default = Config{
|
|||
Highlight: highlight.DefaultConfig,
|
||||
|
||||
Goldmark: goldmark_config.Default,
|
||||
BlackFriday: blackfriday_config.Default,
|
||||
|
||||
AsciidocExt: asciidocext_config.Default,
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,6 @@ func TestConfig(t *testing.T) {
|
|||
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(conf.Goldmark.Renderer.Unsafe, qt.Equals, true)
|
||||
c.Assert(conf.BlackFriday.Fractions, qt.Equals, true)
|
||||
c.Assert(conf.Goldmark.Parser.Attribute.Title, qt.Equals, true)
|
||||
c.Assert(conf.Goldmark.Parser.Attribute.Block, qt.Equals, false)
|
||||
|
||||
|
@ -53,37 +52,4 @@ func TestConfig(t *testing.T) {
|
|||
c.Assert(conf.AsciidocExt.Extensions[0], qt.Equals, "asciidoctor-html5s")
|
||||
})
|
||||
|
||||
c.Run("legacy", func(c *qt.C) {
|
||||
c.Parallel()
|
||||
v := config.New()
|
||||
|
||||
v.Set("blackfriday", map[string]any{
|
||||
"angledQuotes": true,
|
||||
})
|
||||
|
||||
v.Set("footnoteAnchorPrefix", "myprefix")
|
||||
v.Set("footnoteReturnLinkContents", "myreturn")
|
||||
v.Set("pygmentsStyle", "hugo")
|
||||
v.Set("pygmentsCodefencesGuessSyntax", true)
|
||||
|
||||
v.Set("markup", map[string]any{
|
||||
"goldmark": map[string]any{
|
||||
"parser": map[string]any{
|
||||
"attribute": false, // Was changed to a struct in 0.81.0
|
||||
},
|
||||
},
|
||||
})
|
||||
conf, err := Decode(v)
|
||||
|
||||
c.Assert(err, qt.IsNil)
|
||||
c.Assert(conf.BlackFriday.AngledQuotes, qt.Equals, true)
|
||||
c.Assert(conf.BlackFriday.FootnoteAnchorPrefix, qt.Equals, "myprefix")
|
||||
c.Assert(conf.BlackFriday.FootnoteReturnLinkContents, qt.Equals, "myreturn")
|
||||
c.Assert(conf.Highlight.Style, qt.Equals, "hugo")
|
||||
c.Assert(conf.Highlight.CodeFences, qt.Equals, true)
|
||||
c.Assert(conf.Highlight.GuessSyntax, qt.Equals, true)
|
||||
c.Assert(conf.Goldmark.Parser.Attribute.Title, qt.Equals, false)
|
||||
c.Assert(conf.Goldmark.Parser.Attribute.Block, qt.Equals, false)
|
||||
|
||||
})
|
||||
}
|
||||
|
|
|
@ -43,5 +43,4 @@ func TestConverterRegistry(t *testing.T) {
|
|||
checkName("rst")
|
||||
checkName("pandoc")
|
||||
checkName("org")
|
||||
checkName("blackfriday")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue