Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] Hugo doesn't replace some emoji after a ":" #2246

Closed
memiks opened this issue Jul 1, 2016 · 5 comments
Closed

[Bug] Hugo doesn't replace some emoji after a ":" #2246

memiks opened this issue Jul 1, 2016 · 5 comments

Comments

@memiks
Copy link

memiks commented Jul 1, 2016

With the last master head version Hugo is not able to replace emoji after ":" character.

For example this text does not work:

test :

this is a test

test

🆒😊:🍕:blush : : blush: 🍕

So I try to replace code used in emoji.go by regexp, in order to work with all text.

@memiks
Copy link
Author

memiks commented Jul 1, 2016

i will try to contribute through a pull request but it is a little bit complicated to retrieve go package and use local source of Hugo etc...

So for the moment I push my code here : helpers/emoji.go

`
// Copyright 2016 The Hugo Authors. All rights reserved.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package helpers

import (
"regexp"
"sync"
"github.com/kyokomi/emoji"
)

var (
emojiInit sync.Once
regEmoji *regexp.Regexp
emojiMap = make(map[string]string)
)

// Emojify "emojifies" the input source.
// See http://www.emoji-cheat-sheet.com/
func Emojify(source []byte) []byte {
emojiInit.Do(initEmoji)

return []byte (regEmoji.ReplaceAllStringFunc(string(source), EmojiTranslateFunc))

}

func EmojiTranslateFunc(str string) string {
emoji, ok := emojiMap[str]
if ok {
return emoji
}
return str
}

func initEmoji() {
emojiMap = emoji.CodeMap()
regEmoji = regexp.MustCompile(":[a-zA-Z0-9_-]+:")
}

`

@bep
Copy link
Member

bep commented Jul 1, 2016

Duplicate of #2198

@bep bep closed this as completed Jul 1, 2016
bep added a commit that referenced this issue Jul 1, 2016
bep added a commit to bep/hugo that referenced this issue Jul 1, 2016
Out of curiosity more than anything:

```
BenchmarkEmojiRegxp-4              100000         19064 ns/op       17552 B/op          55 allocs/op
BenchmarkEmojiKyokomiFprint-4       20000         86373 ns/op       33960 B/op         117 allocs/op
BenchmarkEmojiKyokomiSprint-4       20000         86308 ns/op       38232 B/op         122 allocs/op
BenchmarkHugoEmoji-4               500000          5721 ns/op         624 B/op          13 allocs/op
```

There may be ways to get less allocation from the regexp case.

See gohugoio#2246
@memiks
Copy link
Author

memiks commented Jul 4, 2016

Yes in fact my tescase does not work with the last version before your last commit @bep
That's why I try to correct it with regular expression.

I see you make speed test ? and corrected issue with an other method ? ok no problem for me ;)

Thanks,
Regards,
Mémîks.

@bep
Copy link
Member

bep commented Jul 4, 2016

I haven't corrected this with another method. I added your test case to master to make sure that we were on the page. It passed. If you tell me that a test case fixed the issue, that sounds weird.

tychoish pushed a commit to tychoish/hugo that referenced this issue Aug 13, 2017
@github-actions
Copy link

github-actions bot commented Apr 5, 2022

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants