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
This commit is contained in:
Joe Mooring
2023-10-24 03:04:13 -07:00
committed by GitHub
parent de4e466036
commit 272484f8bf
16 changed files with 151 additions and 312 deletions

View File

@@ -150,7 +150,7 @@ func (m *pageMap) newPageFromContentNode(n *contentNode, parentBucket *pagesMapB
parseResult, err := pageparser.Parse(
r,
pageparser.Config{EnableEmoji: s.conf.EnableEmoji},
pageparser.Config{},
)
if err != nil {
return nil, err

View File

@@ -794,11 +794,7 @@ Loop:
rn.AddShortcode(currShortcode)
case it.Type == pageparser.TypeEmoji:
if emoji := helpers.Emoji(it.ValStr(result.Input())); emoji != nil {
rn.AddReplacement(emoji, it)
} else {
rn.AddBytes(it)
}
rn.AddBytes(it)
case it.IsEOF():
break Loop
case it.IsError():

View File

@@ -894,13 +894,13 @@ summary: Summary (zh)
b.Build(BuildCfg{})
b.AssertFileContent("public/index.html", `<html>
<body>
<h2>Translations</h2>
<ul>
<li>Title: Title (zh), Summary (zh)</li>
<li>Content: <p>这是一些内容</p>
</li>
@@ -911,7 +911,7 @@ summary: Summary (zh)
<li>Truncated: false</li>
<li>FuzzyWordCount: 100</li>
<li>ReadingTime: 1</li>
<li>Len: 26</li>
<li>Len: 26</li>
</ul>
@@ -921,7 +921,7 @@ summary: Summary (zh)
b.AssertFileContent("public/metadata.html", `<h2>Translations metadata</h2>
<ul>
<li>Title: Title (zh), Summary (zh)</li>
<li>Content: <p>这是一些内容</p>
</li>
@@ -932,13 +932,13 @@ summary: Summary (zh)
<li>Truncated: false</li>
<li>FuzzyWordCount: 100</li>
<li>ReadingTime: 1</li>
<li>Len: 26</li>
<li>Len: 26</li>
</ul>`)
b.AssertFileContent("public/zh_cn/index.html", `<html>
<body>
<h2>Translations</h2>
<ul>
@@ -953,7 +953,7 @@ summary: Summary (zh)
<li>Truncated: false</li>
<li>FuzzyWordCount: 100</li>
<li>ReadingTime: 1</li>
<li>Len: 29</li>
<li>Len: 29</li>
</ul>
@@ -963,7 +963,7 @@ summary: Summary (zh)
b.AssertFileContent("public/zh_cn/metadata.html", `<h2>Translations metadata</h2>
<ul>
<li>Title: Title (en), Summary (en)</li>
<li>Content: <p>Here is some content.</p>
</li>
@@ -974,7 +974,7 @@ summary: Summary (zh)
<li>Truncated: false</li>
<li>FuzzyWordCount: 100</li>
<li>ReadingTime: 1</li>
<li>Len: 29</li>
<li>Len: 29</li>
</ul>`)
}
@@ -1234,60 +1234,6 @@ func TestChompBOM(t *testing.T) {
checkPageTitle(t, p, "Simple")
}
func TestPageWithEmoji(t *testing.T) {
for _, enableEmoji := range []bool{true, false} {
v := config.New()
v.Set("enableEmoji", enableEmoji)
b := newTestSitesBuilder(t).WithViper(v)
b.WithContent("page-emoji.md", `---
title: "Hugo Smile"
---
This is a :smile:.
<!--more-->
Another :smile: This is :not: :an: :emoji:.
O :christmas_tree:
Write me an :e-mail: or :email:?
Too many colons: :: ::: :::: :?: :!: :.:
If you dislike this video, you can hit that :-1: button :stuck_out_tongue_winking_eye:,
but if you like it, hit :+1: and get subscribed!
`)
b.CreateSites().Build(BuildCfg{})
if enableEmoji {
b.AssertFileContent("public/page-emoji/index.html",
"This is a 😄",
"Another 😄",
"This is :not: :an: :emoji:.",
"O 🎄",
"Write me an 📧 or ✉️?",
"Too many colons: :: ::: :::: :?: :!: :.:",
"you can hit that 👎 button 😜,",
"hit 👍 and get subscribed!",
)
} else {
b.AssertFileContent("public/page-emoji/index.html",
"This is a :smile:",
"Another :smile:",
"This is :not: :an: :emoji:.",
"O :christmas_tree:",
"Write me an :e-mail: or :email:?",
"Too many colons: :: ::: :::: :?: :!: :.:",
"you can hit that :-1: button :stuck_out_tongue_winking_eye:,",
"hit :+1: and get subscribed!",
)
}
}
}
func TestPageHTMLContent(t *testing.T) {
b := newTestSitesBuilder(t)
b.WithSimpleConfigFile()
@@ -1333,7 +1279,7 @@ func TestPageManualSummary(t *testing.T) {
title: "Hugo"
---
This is a {{< sc >}}.
<!--more-->
<!--more-->
Content.
`)
@@ -1342,7 +1288,7 @@ Content.
title: "Hugo"
---
{{< sc >}}
<!--more-->
<!--more-->
{{< sc >}}
`)
@@ -1363,7 +1309,7 @@ Summary<!--more-->{{< sc >}}
#+DESCRIPTION: D1
This is a {{< sc >}}.
# more
Content.
Content.
`)
b.WithContent("page-org-variant1.org", `#+TITLE: T1
@@ -1371,7 +1317,7 @@ Summary.
# more
Content.
Content.
`)
b.WithTemplatesAdded("layouts/shortcodes/sc.html", "a shortcode")
@@ -1665,7 +1611,7 @@ SUMMARY:{{ .Summary }}:{{ len .Summary }}:END
b := newTestSitesBuilder(t)
b.WithSimpleConfigFile().WithTemplatesAdded(single...).WithContent("p1.md", fmt.Sprintf(`---
title: p1
title: p1
---
%s

View File

@@ -26,8 +26,6 @@ import (
"strings"
"sync"
"github.com/gohugoio/hugo/helpers"
"errors"
"github.com/gohugoio/hugo/common/herrors"
@@ -632,14 +630,7 @@ Loop:
case currItem.IsText():
sc.inner = append(sc.inner, currItem.ValStr(source))
case currItem.Type == pageparser.TypeEmoji:
// TODO(bep) avoid the duplication of these "text cases", to prevent
// more of #6504 in the future.
val := currItem.ValStr(source)
if emoji := helpers.Emoji(val); emoji != nil {
sc.inner = append(sc.inner, string(emoji))
} else {
sc.inner = append(sc.inner, val)
}
sc.inner = append(sc.inner, currItem.ValStr(source))
case currItem.IsShortcodeName():
sc.name = currItem.ValStr(source)

View File

@@ -599,7 +599,7 @@ weight: %d
c.Assert(len(s.RegularPages()), qt.Equals, 3)
builder.AssertFileContent("public/en/p1/index.html", `v1: 0 sgo: |v2: 1 sgo: 0|v3: 2 sgo: 1|v4: 3 sgo: 2|v5: 4 sgo: 3`)
builder.AssertFileContent("public/en/p1/index.html", `outer ordinal: 5 inner:
builder.AssertFileContent("public/en/p1/index.html", `outer ordinal: 5 inner:
ordinal: 0 scratch ordinal: 1 scratch get ordinal: 0
ordinal: 2 scratch ordinal: 3 scratch get ordinal: 2
ordinal: 4 scratch ordinal: 5 scratch get ordinal: 4`)
@@ -754,33 +754,6 @@ title: "Hugo Rocks!"
)
}
// https://github.com/gohugoio/hugo/issues/6504
func TestShortcodeEmoji(t *testing.T) {
t.Parallel()
v := config.New()
v.Set("enableEmoji", true)
builder := newTestSitesBuilder(t).WithViper(v)
builder.WithContent("page.md", `---
title: "Hugo Rocks!"
---
# doc
{{< event >}}10:30-11:00 My :smile: Event {{< /event >}}
`).WithTemplatesAdded(
"layouts/shortcodes/event.html", `<div>{{ "\u29BE" }} {{ .Inner }} </div>`)
builder.Build(BuildCfg{})
builder.AssertFileContent("public/page/index.html",
"⦾ 10:30-11:00 My 😄 Event",
)
}
func TestShortcodeParams(t *testing.T) {
t.Parallel()
c := qt.New(t)

View File

@@ -94,7 +94,6 @@ type siteConfigHolder struct {
taxonomiesConfig taxonomiesConfig
timeout time.Duration
hasCJKLanguage bool
enableEmoji bool
}
// Lazily loaded site dependencies.