diff options
Diffstat (limited to 'hugolib')
-rw-r--r-- | hugolib/page_content.go | 13 | ||||
-rw-r--r-- | hugolib/page_test.go | 39 | ||||
-rw-r--r-- | hugolib/pagebundler_handlers.go | 4 | ||||
-rw-r--r-- | hugolib/shortcode.go | 12 |
4 files changed, 62 insertions, 6 deletions
diff --git a/hugolib/page_content.go b/hugolib/page_content.go index a363249d5..af13d8a38 100644 --- a/hugolib/page_content.go +++ b/hugolib/page_content.go @@ -17,6 +17,8 @@ import ( "bytes" "io" + "github.com/gohugoio/hugo/helpers" + errors "github.com/pkg/errors" bp "github.com/gohugoio/hugo/bufferpool" @@ -149,6 +151,12 @@ Loop: result.WriteString(placeHolder) ordinal++ s.shortcodes.Add(placeHolder, currShortcode) + case it.Type == pageparser.TypeEmoji: + if emoji := helpers.Emoji(it.ValStr()); emoji != nil { + result.Write(emoji) + } else { + result.Write(it.Val) + } case it.IsEOF(): break Loop case it.IsError(): @@ -170,7 +178,10 @@ Loop: func (p *Page) parse(reader io.Reader) error { - parseResult, err := pageparser.Parse(reader) + parseResult, err := pageparser.Parse( + reader, + pageparser.Config{EnableEmoji: p.s.Cfg.GetBool("enableEmoji")}, + ) if err != nil { return err } diff --git a/hugolib/page_test.go b/hugolib/page_test.go index b8273ce28..9723b1426 100644 --- a/hugolib/page_test.go +++ b/hugolib/page_test.go @@ -1497,6 +1497,45 @@ func TestChompBOM(t *testing.T) { checkPageTitle(t, p, "Simple") } +func TestPageWithEmoji(t *testing.T) { + for _, enableEmoji := range []bool{true, false} { + v := viper.New() + v.Set("enableEmoji", enableEmoji) + b := newTestSitesBuilder(t) + b.WithViper(v) + + b.WithSimpleConfigFile() + + b.WithContent("page-emoji.md", `--- +title: "Hugo Smile" +--- +This is a :smile:. +<!--more--> + +Another :smile: This is :not: an emoji. + +`) + + b.CreateSites().Build(BuildCfg{}) + + if enableEmoji { + b.AssertFileContent("public/page-emoji/index.html", + "This is a 😄", + "Another 😄", + "This is :not: an emoji", + ) + } else { + b.AssertFileContent("public/page-emoji/index.html", + "This is a :smile:", + "Another :smile:", + "This is :not: an emoji", + ) + } + + } + +} + // https://github.com/gohugoio/hugo/issues/5381 func TestPageManualSummary(t *testing.T) { b := newTestSitesBuilder(t) diff --git a/hugolib/pagebundler_handlers.go b/hugolib/pagebundler_handlers.go index 2ab0ebafe..fdff76e24 100644 --- a/hugolib/pagebundler_handlers.go +++ b/hugolib/pagebundler_handlers.go @@ -272,10 +272,6 @@ func (c *contentHandlers) handlePageContent() contentHandler { p := ctx.currentPage - if c.s.Cfg.GetBool("enableEmoji") { - p.workContent = helpers.Emojify(p.workContent) - } - p.workContent = p.renderContent(p.workContent) tmpContent, tmpTableOfContents := helpers.ExtractTOC(p.workContent) diff --git a/hugolib/shortcode.go b/hugolib/shortcode.go index 8be312f83..db7bf2c62 100644 --- a/hugolib/shortcode.go +++ b/hugolib/shortcode.go @@ -177,6 +177,16 @@ type shortcode struct { pos int // the position in bytes in the source file } +func (s shortcode) innerString() string { + var sb strings.Builder + + for _, inner := range s.inner { + sb.WriteString(inner.(string)) + } + + return sb.String() +} + func (sc shortcode) String() string { // for testing (mostly), so any change here will break tests! var params interface{} @@ -363,7 +373,7 @@ func renderShortcode( if sc.isInline { templName := path.Join("_inline_shortcode", p.Path(), sc.name) if sc.isClosing { - templStr := sc.inner[0].(string) + templStr := sc.innerString() var err error tmpl, err = p.s.TextTmpl.Parse(templName, templStr) |