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

github.com/gohugoio/hugo.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/markup
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-28 12:01:47 +0300
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>2022-05-29 12:50:58 +0300
commit0f8dc47037f59156c04540d97ed1b588e6bc1164 (patch)
tree78d76bb4d52b2f35b609013fde6ec4f5e19730c8 /markup
parent3b478f50b7408ad78d085fa6dbc3c7a683c9d943 (diff)
Remove Blackfriday markdown engine
It has been deprecated for a long time, its v1 version is not maintained anymore, and there are many known issues. Goldmark should be a mature replacement by now. Closes #9934
Diffstat (limited to 'markup')
-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
10 files changed, 44 insertions, 685 deletions
diff --git a/markup/blackfriday/anchors.go b/markup/blackfriday/anchors.go
new file mode 100644
index 000000000..90f65a64c
--- /dev/null
+++ b/markup/blackfriday/anchors.go
@@ -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)
+}
diff --git a/markup/blackfriday/blackfriday_config/config.go b/markup/blackfriday/blackfriday_config/config.go
deleted file mode 100644
index 8c276c9f6..000000000
--- a/markup/blackfriday/blackfriday_config/config.go
+++ /dev/null
@@ -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
-}
diff --git a/markup/blackfriday/convert.go b/markup/blackfriday/convert.go
deleted file mode 100644
index b786e29de..000000000
--- a/markup/blackfriday/convert.go
+++ /dev/null
@@ -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)
-)
diff --git a/markup/blackfriday/convert_test.go b/markup/blackfriday/convert_test.go
deleted file mode 100644
index 0d691f646..000000000
--- a/markup/blackfriday/convert_test.go
+++ /dev/null
@@ -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)
- }
- }
-}
diff --git a/markup/blackfriday/renderer.go b/markup/blackfriday/renderer.go
deleted file mode 100644
index 5d4cab048..000000000
--- a/markup/blackfriday/renderer.go
+++ /dev/null
@@ -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)
- }
- }
-}
diff --git a/markup/converter/converter.go b/markup/converter/converter.go
index 1ea301aa6..c760381f4 100644
--- a/markup/converter/converter.go
+++ b/markup/converter/converter.go
@@ -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.
diff --git a/markup/markup.go b/markup/markup.go
index 13e5f3042..f5e46ad90 100644
--- a/markup/markup.go
+++ b/markup/markup.go
@@ -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.
diff --git a/markup/markup_config/config.go b/markup/markup_config/config.go
index ddcba8c3a..e254ba7a0 100644
--- a/markup/markup_config/config.go
+++ b/markup/markup_config/config.go
@@ -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,
}
diff --git a/markup/markup_config/config_test.go b/markup/markup_config/config_test.go
index 06bd0b11c..a320e6912 100644
--- a/markup/markup_config/config_test.go
+++ b/markup/markup_config/config_test.go
@@ -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)
-
- })
}
diff --git a/markup/markup_test.go b/markup/markup_test.go
index c0cc5ba8b..5ec27c45c 100644
--- a/markup/markup_test.go
+++ b/markup/markup_test.go
@@ -43,5 +43,4 @@ func TestConverterRegistry(t *testing.T) {
checkName("rst")
checkName("pandoc")
checkName("org")
- checkName("blackfriday")
}