Skip to content
/ hugo Public
forked from gohugoio/hugo

Commit

Permalink
markdown: Add yuin/goldmark-emoji
Browse files Browse the repository at this point in the history
  • Loading branch information
jmooring committed Oct 22, 2023
1 parent de4e466 commit 8fc55c3
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 3 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ require (
github.com/tdewolff/minify/v2 v2.12.9
github.com/tdewolff/parse/v2 v2.6.8
github.com/yuin/goldmark v1.5.6
github.com/yuin/goldmark-emoji v1.0.2
go.uber.org/atomic v1.11.0
go.uber.org/automaxprocs v1.5.3
gocloud.dev v0.34.0
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -444,9 +444,12 @@ github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.2.1/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.3.7/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1Zlc8k=
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/goldmark v1.5.6 h1:COmQAWTCcGetChm3Ig7G/t8AFAN00t+o8Mt4cf7JpwA=
github.com/yuin/goldmark v1.5.6/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY=
github.com/yuin/goldmark-emoji v1.0.2 h1:c/RgTShNgHTtc6xdz2KKI74jJr6rWi7FPgnP9GAsO5s=
github.com/yuin/goldmark-emoji v1.0.2/go.mod h1:RhP/RWpexdp+KHs7ghKnifRoIs/Bq4nDS7tRbCkOwKY=
go.opencensus.io v0.21.0/go.mod h1:mSImk1erAIZhrmZN+AvHh14ztQfjbGwt4TtuofqLduU=
go.opencensus.io v0.22.0/go.mod h1:+kGneAE2xo2IficOXnaByMWTGM9T73dGwxeWcUqIpI8=
go.opencensus.io v0.22.2/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw=
Expand Down
6 changes: 6 additions & 0 deletions markup/goldmark/convert.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -149,13 +150,18 @@ func newMarkdown(pcfg converter.ProviderConfig) goldmark.Markdown {
extensions = append(extensions, c)
}

if cfg.Extensions.Emoji {
extensions = append(extensions, emoji.Emoji)
}

if cfg.Parser.AutoHeadingID {
parserOptions = append(parserOptions, parser.WithAutoHeadingID())
}

if cfg.Parser.Attribute.Title {
parserOptions = append(parserOptions, parser.WithAttribute())
}

if cfg.Parser.Attribute.Block {
extensions = append(extensions, attributes.New())
}
Expand Down
2 changes: 2 additions & 0 deletions markup/goldmark/goldmark_config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ var Default = Config{
},
Footnote: true,
DefinitionList: true,
Emoji: false,
Table: true,
Strikethrough: true,
Linkify: true,
Expand Down Expand Up @@ -74,6 +75,7 @@ type Extensions struct {
Typographer Typographer
Footnote bool
DefinitionList bool
Emoji bool

// GitHub flavored markdown
Table bool
Expand Down
52 changes: 49 additions & 3 deletions markup/goldmark/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 --
Expand All @@ -421,8 +421,8 @@ title: "p1"
https://example.org
a@b.com
`

files = strings.ReplaceAll(files, "RENDERFUNC", renderFunc)
Expand Down Expand Up @@ -578,3 +578,49 @@ a <!-- b --> c
"<li>This is a list item <!-- Comment: an innocent-looking comment --></li>",
)
}

func TestGoldmarkEmojiExtension(t *testing.T) {
t.Parallel()

files := `
-- config.toml --
# Must set enableEmoji to false if goldmark/emoji extension is enabled.
# This is expected behavior.
enableEmoji = false
[markup.goldmark.extensions]
emoji = true
-- content/p1.md --
---
title: "p1"
---
~~~text
:x:
~~~
{{% include "/p2" %}}
-- content/p2.md --
---
title: "p2"
---
:heavy_check_mark:
-- layouts/shortcodes/include.html --
{{ $p := site.GetPage (.Get 0) }}
{{ $p.RenderShortcodes }}
-- 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>",
)
}

0 comments on commit 8fc55c3

Please sign in to comment.