diff options
author | Joe Mooring <joe@mooring.com> | 2023-10-24 03:04:13 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-10-24 12:04:13 +0200 |
commit | 272484f8bfab97dbadad49a638a3e4b6af499f15 (patch) | |
tree | 39853fd0d9a1c7e28372777e0924497cc26607b2 /hugolib | |
parent | de4e466036026e9a5805155f00882b93267231b5 (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 'hugolib')
-rw-r--r-- | hugolib/content_map_page.go | 2 | ||||
-rw-r--r-- | hugolib/page.go | 6 | ||||
-rw-r--r-- | hugolib/page_test.go | 84 | ||||
-rw-r--r-- | hugolib/shortcode.go | 11 | ||||
-rw-r--r-- | hugolib/shortcode_test.go | 29 | ||||
-rw-r--r-- | hugolib/site.go | 1 |
6 files changed, 19 insertions, 114 deletions
diff --git a/hugolib/content_map_page.go b/hugolib/content_map_page.go index e7f6c5aed..2c14ffa59 100644 --- a/hugolib/content_map_page.go +++ b/hugolib/content_map_page.go @@ -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 diff --git a/hugolib/page.go b/hugolib/page.go index 5b2411441..48f4c9d2b 100644 --- a/hugolib/page.go +++ b/hugolib/page.go @@ -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(): diff --git a/hugolib/page_test.go b/hugolib/page_test.go index ecaf1dc5c..7e34f0499 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -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 diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index e201d4d6b..8edfab118 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -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) diff --git a/hugolib/shortcode_test.go b/hugolib/shortcode_test.go index 6ee68673f..ff9ae35fc 100644 --- a/hugolib/shortcode_test.go +++ b/hugolib/shortcode_test.go @@ -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) diff --git a/hugolib/site.go b/hugolib/site.go index 863b5c4b7..c682eebc9 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -94,7 +94,6 @@ type siteConfigHolder struct { taxonomiesConfig taxonomiesConfig timeout time.Duration hasCJKLanguage bool - enableEmoji bool } // Lazily loaded site dependencies. |