Remove mmark
authorBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 4 Jan 2022 12:26:23 +0000 (13:26 +0100)
committerBjørn Erik Pedersen <bjorn.erik.pedersen@gmail.com>
Tue, 4 Jan 2022 16:10:39 +0000 (17:10 +0100)
Closes #9350

go.mod
go.sum
helpers/content.go
helpers/general_test.go
hugolib/page_test.go
hugolib/shortcode_test.go
markup/markup.go
markup/markup_test.go
markup/mmark/convert.go [deleted file]
markup/mmark/convert_test.go [deleted file]
markup/mmark/renderer.go [deleted file]

diff --git a/go.mod b/go.mod
index a2cee7dba0bde4f1d6c38905b0ce5fa44e24c6e5..f10b4a91e6659311c82bd02c5f850bf3766922b2 100644 (file)
--- a/go.mod
+++ b/go.mod
@@ -36,7 +36,6 @@ require (
        github.com/kyokomi/emoji/v2 v2.2.8
        github.com/magefile/mage v1.11.0
        github.com/mattn/go-isatty v0.0.14
-       github.com/miekg/mmark v1.3.6
        github.com/mitchellh/hashstructure v1.1.0
        github.com/mitchellh/mapstructure v1.4.3
        github.com/muesli/smartcrop v0.3.0
diff --git a/go.sum b/go.sum
index c0cac3effc6aafa5468e60ffbd23f161bff555e4..fa4bc50416b9780487831a8cb921ccf676b79393 100644 (file)
--- a/go.sum
+++ b/go.sum
@@ -420,8 +420,6 @@ github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27k
 github.com/mattn/go-runewidth v0.0.9 h1:Lm995f3rfxdpd6TSmuVCHVb/QhupuXlYr8sCI/QdE+0=
 github.com/mattn/go-runewidth v0.0.9/go.mod h1:H031xJmbD/WCDINGzjvQ9THkh0rPKHF+m2gUSrubnMI=
 github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
-github.com/miekg/mmark v1.3.6 h1:t47x5vThdwgLJzofNsbsAl7gmIiJ7kbDQN5BxwBmwvY=
-github.com/miekg/mmark v1.3.6/go.mod h1:w7r9mkTvpS55jlfyn22qJ618itLryxXBhA7Jp3FIlkw=
 github.com/mitchellh/cli v1.0.0/go.mod h1:hNIlj7HEI86fIcpObd7a0FcrxTWetlwJDGcceTlRvqc=
 github.com/mitchellh/go-homedir v1.0.0/go.mod h1:SfyaCUpYCn1Vlf4IUYiD9fPX4A5wJrkLzIz1N1q0pr0=
 github.com/mitchellh/go-homedir v1.1.0 h1:lukF9ziXFxDFPkA1vsr5zpc1XuPDn/wFntq5mG+4E0Y=
index 2d26a0c488085bd14bcc9a9ac2edf6d9b9e33e77..080e31909df45361f2ca8e5c181570c0b5477724 100644 (file)
@@ -215,9 +215,6 @@ func (c *ContentSpec) ResolveMarkup(in string) string {
        case "html", "htm":
                return "html"
        default:
-               if in == "mmark" {
-                       Deprecated("Markup type mmark", "See https://gohugo.io//content-management/formats/#list-of-content-formats", true)
-               }
                if conv := c.Converters.Get(in); conv != nil {
                        return conv.Name()
                }
index db8cb30a84921d996b41fd0bdcc45d57f83aee28..7fe00c51a632c7c9d727b0b2675a7d3e9cea9341 100644 (file)
@@ -46,7 +46,6 @@ func TestResolveMarkup(t *testing.T) {
                {"rst", "rst"},
                {"pandoc", "pandoc"},
                {"pdc", "pandoc"},
-               {"mmark", "mmark"},
                {"html", "html"},
                {"htm", "html"},
                {"org", "org"},
index c59177652ccf7b7e6fe67f5ff13635b1dd8e5cdb..7d55787c8e3dc5536a10f16fd0c97f8d8cfa4dd0 100644 (file)
@@ -375,7 +375,6 @@ func testAllMarkdownEnginesForPages(t *testing.T,
                shouldExecute func() bool
        }{
                {"md", func() bool { return true }},
-               {"mmark", func() bool { return true }},
                {"ad", func() bool { return asciidocext.Supports() }},
                {"rst", func() bool { return rst.Supports() }},
        }
index 6316afc98e637922d6299be74f46142bb9357c0a..9fc9a9675fbabdd05f574d8cbd3271ebd5436563 100644 (file)
@@ -533,17 +533,7 @@ e`,
                        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>",
                },
-               {
-                       "sect/doc9.mmark", `
----
-menu:
-  main:
-    parent: 'parent'
----
-**Shortcodes:** *b: {{< b >}} c: {{% c %}}*`,
-                       filepath.FromSlash("public/sect/doc9/index.html"),
-                       "<p><strong>Shortcodes:</strong> <em>b: b c: c</em></p>\n",
-               },
+
                // Issue #1229: Menus not available in shortcode.
                {
                        "sect/doc10.md", `---
@@ -562,6 +552,9 @@ tags:
                        "sect/doc11.md", `---
 tags:
 - Bugs
+menu:
+  main:
+    parent: 'parent'
 ---
 **Tags:** {{< tags >}}`,
                        filepath.FromSlash("public/sect/doc11/index.html"),
@@ -1390,7 +1383,7 @@ outputs: ["html", "css", "csv", "json"]
 
                b.Build(BuildCfg{})
 
-               //helpers.PrintFs(b.Fs.Destination, "public", os.Stdout)
+               // helpers.PrintFs(b.Fs.Destination, "public", os.Stdout)
 
                for i := 0; i < numPages; i++ {
                        b.AssertFileContent(fmt.Sprintf("public/page%d/index.html", i), "Short-HTML")
index 31fa6b0f7be4bba35b18aed30ea9f8e7ad1c40ec..287db7369ecd5f4810c48e4068db4bda6ac96bf7 100644 (file)
@@ -27,7 +27,6 @@ import (
        "github.com/gohugoio/hugo/markup/asciidocext"
        "github.com/gohugoio/hugo/markup/blackfriday"
        "github.com/gohugoio/hugo/markup/converter"
-       "github.com/gohugoio/hugo/markup/mmark"
        "github.com/gohugoio/hugo/markup/pandoc"
        "github.com/gohugoio/hugo/markup/rst"
 )
@@ -73,9 +72,6 @@ func NewConverterProvider(cfg converter.ProviderConfig) (ConverterProvider, erro
        if err := add(blackfriday.Provider); err != nil {
                return nil, err
        }
-       if err := add(mmark.Provider); err != nil {
-               return nil, err
-       }
        if err := add(asciidocext.Provider, "ad", "adoc"); err != nil {
                return nil, err
        }
index 71d39075dc72f1045b4f0ebdd51a582fb7f1fb52..c0cc5ba8bc51a8427d66a9b6f694109894ff7b03 100644 (file)
@@ -39,7 +39,6 @@ func TestConverterRegistry(t *testing.T) {
        c.Assert(r.Get("markdown").Name(), qt.Equals, "goldmark")
 
        checkName("goldmark")
-       checkName("mmark")
        checkName("asciidocext")
        checkName("rst")
        checkName("pandoc")
diff --git a/markup/mmark/convert.go b/markup/mmark/convert.go
deleted file mode 100644 (file)
index b4cc8b0..0000000
+++ /dev/null
@@ -1,137 +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 mmark converts Markdown to HTML using MMark v1.
-package mmark
-
-import (
-       "github.com/gohugoio/hugo/identity"
-       "github.com/gohugoio/hugo/markup/blackfriday/blackfriday_config"
-       "github.com/gohugoio/hugo/markup/converter"
-       "github.com/miekg/mmark"
-)
-
-// Provider is the package entry point.
-var Provider converter.ProviderProvider = provider{}
-
-type provider struct {
-}
-
-func (p provider) New(cfg converter.ProviderConfig) (converter.Provider, error) {
-       defaultBlackFriday := cfg.MarkupConfig.BlackFriday
-       defaultExtensions := getMmarkExtensions(defaultBlackFriday)
-
-       return converter.NewProvider("mmark", func(ctx converter.DocumentContext) (converter.Converter, error) {
-               b := defaultBlackFriday
-               extensions := defaultExtensions
-
-               if ctx.ConfigOverrides != nil {
-                       var err error
-                       b, err = blackfriday_config.UpdateConfig(b, ctx.ConfigOverrides)
-                       if err != nil {
-                               return nil, err
-                       }
-                       extensions = getMmarkExtensions(b)
-               }
-
-               return &mmarkConverter{
-                       ctx:        ctx,
-                       b:          b,
-                       extensions: extensions,
-                       cfg:        cfg,
-               }, nil
-       }), nil
-}
-
-type mmarkConverter struct {
-       ctx        converter.DocumentContext
-       extensions int
-       b          blackfriday_config.Config
-       cfg        converter.ProviderConfig
-}
-
-func (c *mmarkConverter) Convert(ctx converter.RenderContext) (converter.Result, error) {
-       r := getHTMLRenderer(c.ctx, c.b, c.cfg)
-       return mmark.Parse(ctx.Src, r, c.extensions), nil
-}
-
-func (c *mmarkConverter) Supports(feature identity.Identity) bool {
-       return false
-}
-
-func getHTMLRenderer(
-       ctx converter.DocumentContext,
-       cfg blackfriday_config.Config,
-       pcfg converter.ProviderConfig) mmark.Renderer {
-       var (
-               flags      int
-               documentID string
-       )
-
-       documentID = ctx.DocumentID
-
-       renderParameters := mmark.HtmlRendererParameters{
-               FootnoteAnchorPrefix:       cfg.FootnoteAnchorPrefix,
-               FootnoteReturnLinkContents: cfg.FootnoteReturnLinkContents,
-       }
-
-       if documentID != "" && !cfg.PlainIDAnchors {
-               renderParameters.FootnoteAnchorPrefix = documentID + ":" + renderParameters.FootnoteAnchorPrefix
-       }
-
-       htmlFlags := flags
-       htmlFlags |= mmark.HTML_FOOTNOTE_RETURN_LINKS
-
-       return &mmarkRenderer{
-               BlackfridayConfig: cfg,
-               Config:            pcfg,
-               Renderer:          mmark.HtmlRendererWithParameters(htmlFlags, "", "", renderParameters),
-       }
-}
-
-func getMmarkExtensions(cfg blackfriday_config.Config) int {
-       flags := 0
-       flags |= mmark.EXTENSION_TABLES
-       flags |= mmark.EXTENSION_FENCED_CODE
-       flags |= mmark.EXTENSION_AUTOLINK
-       flags |= mmark.EXTENSION_SPACE_HEADERS
-       flags |= mmark.EXTENSION_CITATION
-       flags |= mmark.EXTENSION_TITLEBLOCK_TOML
-       flags |= mmark.EXTENSION_HEADER_IDS
-       flags |= mmark.EXTENSION_AUTO_HEADER_IDS
-       flags |= mmark.EXTENSION_UNIQUE_HEADER_IDS
-       flags |= mmark.EXTENSION_FOOTNOTES
-       flags |= mmark.EXTENSION_SHORT_REF
-       flags |= mmark.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK
-       flags |= mmark.EXTENSION_INCLUDE
-
-       for _, extension := range cfg.Extensions {
-               if flag, ok := mmarkExtensionMap[extension]; ok {
-                       flags |= flag
-               }
-       }
-       return flags
-}
-
-var mmarkExtensionMap = map[string]int{
-       "tables":                 mmark.EXTENSION_TABLES,
-       "fencedCode":             mmark.EXTENSION_FENCED_CODE,
-       "autolink":               mmark.EXTENSION_AUTOLINK,
-       "laxHtmlBlocks":          mmark.EXTENSION_LAX_HTML_BLOCKS,
-       "spaceHeaders":           mmark.EXTENSION_SPACE_HEADERS,
-       "hardLineBreak":          mmark.EXTENSION_HARD_LINE_BREAK,
-       "footnotes":              mmark.EXTENSION_FOOTNOTES,
-       "noEmptyLineBeforeBlock": mmark.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK,
-       "headerIds":              mmark.EXTENSION_HEADER_IDS,
-       "autoHeaderIds":          mmark.EXTENSION_AUTO_HEADER_IDS,
-}
diff --git a/markup/mmark/convert_test.go b/markup/mmark/convert_test.go
deleted file mode 100644 (file)
index 414e023..0000000
+++ /dev/null
@@ -1,72 +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 mmark
-
-import (
-       "testing"
-
-       "github.com/gohugoio/hugo/config"
-
-       "github.com/gohugoio/hugo/common/loggers"
-
-       qt "github.com/frankban/quicktest"
-       "github.com/gohugoio/hugo/markup/blackfriday/blackfriday_config"
-       "github.com/gohugoio/hugo/markup/converter"
-       "github.com/miekg/mmark"
-)
-
-func TestGetMmarkExtensions(t *testing.T) {
-       b := blackfriday_config.Default
-
-       // TODO: This is doing the same just with different marks...
-       type data struct {
-               testFlag int
-       }
-
-       b.Extensions = []string{"tables"}
-       b.ExtensionsMask = []string{""}
-       allExtensions := []data{
-               {mmark.EXTENSION_TABLES},
-               {mmark.EXTENSION_FENCED_CODE},
-               {mmark.EXTENSION_AUTOLINK},
-               {mmark.EXTENSION_SPACE_HEADERS},
-               {mmark.EXTENSION_CITATION},
-               {mmark.EXTENSION_TITLEBLOCK_TOML},
-               {mmark.EXTENSION_HEADER_IDS},
-               {mmark.EXTENSION_AUTO_HEADER_IDS},
-               {mmark.EXTENSION_UNIQUE_HEADER_IDS},
-               {mmark.EXTENSION_FOOTNOTES},
-               {mmark.EXTENSION_SHORT_REF},
-               {mmark.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK},
-               {mmark.EXTENSION_INCLUDE},
-       }
-
-       actualFlags := getMmarkExtensions(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 TestConvert(t *testing.T) {
-       c := qt.New(t)
-       p, err := Provider.New(converter.ProviderConfig{Cfg: config.New(), Logger: loggers.NewErrorLogger()})
-       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")
-}
diff --git a/markup/mmark/renderer.go b/markup/mmark/renderer.go
deleted file mode 100644 (file)
index 6cb7f10..0000000
+++ /dev/null
@@ -1,42 +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 mmark
-
-import (
-       "bytes"
-       "strings"
-
-       "github.com/gohugoio/hugo/markup/blackfriday/blackfriday_config"
-       "github.com/gohugoio/hugo/markup/converter"
-       "github.com/miekg/mmark"
-)
-
-// hugoHTMLRenderer wraps a blackfriday.Renderer, typically a blackfriday.Html
-// adding some custom behaviour.
-type mmarkRenderer struct {
-       Config            converter.ProviderConfig
-       BlackfridayConfig blackfriday_config.Config
-       mmark.Renderer
-}
-
-// BlockCode renders a given text as a block of code.
-func (r *mmarkRenderer) BlockCode(out *bytes.Buffer, text []byte, lang string, caption []byte, subfigure bool, callouts bool) {
-       if r.Config.MarkupConfig.Highlight.CodeFences {
-               str := strings.Trim(string(text), "\n\r")
-               highlighted, _ := r.Config.Highlight(str, lang, "")
-               out.WriteString(highlighted)
-       } else {
-               r.Renderer.BlockCode(out, text, lang, caption, subfigure, callouts)
-       }
-}