summaryrefslogtreecommitdiffstats
path: root/markup
diff options
context:
space:
mode:
authorJoe Mooring <joe@mooring.com>2023-10-24 03:04:13 -0700
committerGitHub <noreply@github.com>2023-10-24 12:04:13 +0200
commit272484f8bfab97dbadad49a638a3e4b6af499f15 (patch)
tree39853fd0d9a1c7e28372777e0924497cc26607b2 /markup
parentde4e466036026e9a5805155f00882b93267231b5 (diff)
markdown: Pass emoji codes to yuin/goldmark-emoji
Removes emoji code conversion from the page and shortcode parsers. Emoji codes in markdown are now passed to Goldmark, where the goldmark-emoji extension converts them to decimal numeric character references. This disables emoji rendering for the alternate content formats: html, asciidoc, org, pandoc, and rst. Fixes #7332 Fixes #11587 Closes #11598
Diffstat (limited to 'markup')
-rw-r--r--markup/goldmark/convert.go6
-rw-r--r--markup/goldmark/integration_test.go117
2 files changed, 120 insertions, 3 deletions
diff --git a/markup/goldmark/convert.go b/markup/goldmark/convert.go
index fa2ab548b..d66687783 100644
--- a/markup/goldmark/convert.go
+++ b/markup/goldmark/convert.go
@@ -28,6 +28,7 @@ import (
"github.com/gohugoio/hugo/markup/converter"
"github.com/gohugoio/hugo/markup/tableofcontents"
"github.com/yuin/goldmark"
+ emoji "github.com/yuin/goldmark-emoji"
"github.com/yuin/goldmark/ast"
"github.com/yuin/goldmark/extension"
"github.com/yuin/goldmark/parser"
@@ -149,6 +150,10 @@ func newMarkdown(pcfg converter.ProviderConfig) goldmark.Markdown {
extensions = append(extensions, c)
}
+ if pcfg.Conf.EnableEmoji() {
+ extensions = append(extensions, emoji.Emoji)
+ }
+
if cfg.Parser.AutoHeadingID {
parserOptions = append(parserOptions, parser.WithAutoHeadingID())
}
@@ -156,6 +161,7 @@ func newMarkdown(pcfg converter.ProviderConfig) goldmark.Markdown {
if cfg.Parser.Attribute.Title {
parserOptions = append(parserOptions, parser.WithAttribute())
}
+
if cfg.Parser.Attribute.Block {
extensions = append(extensions, attributes.New())
}
diff --git a/markup/goldmark/integration_test.go b/markup/goldmark/integration_test.go
index 84617b2c8..fdcbf4975 100644
--- a/markup/goldmark/integration_test.go
+++ b/markup/goldmark/integration_test.go
@@ -410,7 +410,7 @@ func TestHookInfiniteRecursion(t *testing.T) {
files := `
-- config.toml --
-- layouts/_default/_markup/render-link.html --
-<a href="{{ .Destination | safeURL }}">{{ .Text | RENDERFUNC }}</a>
+<a href="{{ .Destination | safeURL }}">{{ .Text | RENDERFUNC }}</a>
-- layouts/_default/single.html --
{{ .Content }}
-- content/p1.md --
@@ -421,8 +421,8 @@ title: "p1"
https://example.org
a@b.com
-
-
+
+
`
files = strings.ReplaceAll(files, "RENDERFUNC", renderFunc)
@@ -578,3 +578,114 @@ a <!-- b --> c
"<li>This is a list item <!-- Comment: an innocent-looking comment --></li>",
)
}
+
+// Issue #7332
+// Issue #11587
+func TestGoldmarkEmojiExtension(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- config.toml --
+enableEmoji = true
+-- content/p1.md --
+---
+title: "p1"
+---
+~~~text
+:x:
+~~~
+
+{{% include "/p2" %}}
+
+{{< sc1 >}}:smiley:{{< /sc1 >}}
+
+{{< sc2 >}}:+1:{{< /sc2 >}}
+
+{{% sc3 %}}:-1:{{% /sc3 %}}
+
+-- content/p2.md --
+---
+title: "p2"
+---
+:heavy_check_mark:
+-- layouts/shortcodes/include.html --
+{{ $p := site.GetPage (.Get 0) }}
+{{ $p.RenderShortcodes }}
+-- layouts/shortcodes/sc1.html --
+sc1_begin|{{ .Inner }}|sc1_end
+-- layouts/shortcodes/sc2.html --
+sc2_begin|{{ .Inner | .Page.RenderString }}|sc2_end
+-- layouts/shortcodes/sc3.html --
+sc3_begin|{{ .Inner }}|sc3_end
+-- layouts/_default/single.html --
+{{ .Content }}
+`
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ },
+ ).Build()
+
+ b.AssertFileContentExact("public/p1/index.html",
+ // Issue #7332
+ "<span>:x:\n</span>",
+ // Issue #11587
+ "<p>&#x2714;&#xfe0f;</p>",
+ // Should not be converted to emoji
+ "sc1_begin|:smiley:|sc1_end",
+ // Should be converted to emoji
+ "sc2_begin|&#x1f44d;|sc2_end",
+ // Should be converted to emoji
+ "sc3_begin|&#x1f44e;|sc3_end",
+ )
+}
+
+func TestEmojiDisabled(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- config.toml --
+enableEmoji = false
+-- content/p1.md --
+---
+title: "p1"
+---
+:x:
+-- layouts/_default/single.html --
+{{ .Content }}
+`
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ },
+ ).Build()
+
+ b.AssertFileContentExact("public/p1/index.html", "<p>:x:</p>")
+}
+
+func TestEmojiDefaultConfig(t *testing.T) {
+ t.Parallel()
+
+ files := `
+-- content/p1.md --
+---
+title: "p1"
+---
+:x:
+-- layouts/_default/single.html --
+{{ .Content }}
+`
+
+ b := hugolib.NewIntegrationTestBuilder(
+ hugolib.IntegrationTestConfig{
+ T: t,
+ TxtarString: files,
+ },
+ ).Build()
+
+ b.AssertFileContentExact("public/p1/index.html", "<p>:x:</p>")
+}