aboutsummaryrefslogtreecommitdiffhomepage
path: root/helpers/content.go
diff options
context:
space:
mode:
authorBjørn Erik Pedersen <[email protected]>2019-11-06 20:10:47 +0100
committerBjørn Erik Pedersen <[email protected]>2019-11-23 14:12:24 +0100
commitbfb9613a14ab2d93a4474e5486d22e52a9d5e2b3 (patch)
tree81c4dbd10505e952489e1dbcf1d7bafc88b57c28 /helpers/content.go
parenta3fe5e5e35f311f22b6b4fc38abfcf64cd2c7d6f (diff)
downloadhugo-bfb9613a14ab2d93a4474e5486d22e52a9d5e2b3.tar.gz
hugo-bfb9613a14ab2d93a4474e5486d22e52a9d5e2b3.zip
Add Goldmark as the new default markdown handler
This commit adds the fast and CommonMark compliant Goldmark as the new default markdown handler in Hugo. If you want to continue using BlackFriday as the default for md/markdown extensions, you can use this configuration: ```toml [markup] defaultMarkdownHandler="blackfriday" ``` Fixes #5963 Fixes #1778 Fixes #6355
Diffstat (limited to 'helpers/content.go')
-rw-r--r--helpers/content.go45
1 files changed, 15 insertions, 30 deletions
diff --git a/helpers/content.go b/helpers/content.go
index 357bd48e7..941475461 100644
--- a/helpers/content.go
+++ b/helpers/content.go
@@ -32,7 +32,6 @@ import (
bp "github.com/gohugoio/hugo/bufferpool"
"github.com/gohugoio/hugo/config"
"github.com/spf13/afero"
- jww "github.com/spf13/jwalterweatherman"
"strings"
)
@@ -58,9 +57,6 @@ type ContentSpec struct {
BuildExpired bool
BuildDrafts bool
- Highlight func(code, lang, optsStr string) (string, error)
- defatultPygmentsOpts map[string]string
-
Cfg config.Provider
}
@@ -77,36 +73,10 @@ func NewContentSpec(cfg config.Provider, logger *loggers.Logger, contentFs afero
Cfg: cfg,
}
- // Highlighting setup
- options, err := parseDefaultPygmentsOpts(cfg)
- if err != nil {
- return nil, err
- }
- spec.defatultPygmentsOpts = options
-
- // Use the Pygmentize on path if present
- useClassic := false
- h := newHiglighters(spec)
-
- if cfg.GetBool("pygmentsUseClassic") {
- if !hasPygments() {
- jww.WARN.Println("Highlighting with pygmentsUseClassic set requires Pygments to be installed and in the path")
- } else {
- useClassic = true
- }
- }
-
- if useClassic {
- spec.Highlight = h.pygmentsHighlight
- } else {
- spec.Highlight = h.chromaHighlight
- }
-
converterProvider, err := markup.NewConverterProvider(converter.ProviderConfig{
Cfg: cfg,
ContentFs: contentFs,
Logger: logger,
- Highlight: spec.Highlight,
})
if err != nil {
return nil, err
@@ -220,6 +190,21 @@ func (c *ContentSpec) RenderMarkdown(src []byte) ([]byte, error) {
return b.Bytes(), nil
}
+func (c *ContentSpec) ResolveMarkup(in string) string {
+ in = strings.ToLower(in)
+ switch in {
+ case "md", "markdown", "mdown":
+ return "markdown"
+ case "html", "htm":
+ return "html"
+ default:
+ if conv := c.Converters.Get(in); conv != nil {
+ return conv.Name()
+ }
+ }
+ return ""
+}
+
// TotalWords counts instance of one or more consecutive white space
// characters, as defined by unicode.IsSpace, in s.
// This is a cheaper way of word counting than the obvious len(strings.Fields(s)).