mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-13 20:24:00 +02:00
committed by
Bjørn Erik Pedersen
parent
7cb8107735
commit
b6635e1baf
@@ -34,7 +34,6 @@ var (
|
|||||||
// Note that the input byte slice will be modified if needed.
|
// Note that the input byte slice will be modified if needed.
|
||||||
// See http://www.emoji-cheat-sheet.com/
|
// See http://www.emoji-cheat-sheet.com/
|
||||||
func Emojify(source []byte) []byte {
|
func Emojify(source []byte) []byte {
|
||||||
|
|
||||||
emojiInit.Do(initEmoji)
|
emojiInit.Do(initEmoji)
|
||||||
|
|
||||||
start := 0
|
start := 0
|
||||||
@@ -54,7 +53,7 @@ func Emojify(source []byte) []byte {
|
|||||||
nextWordDelim := bytes.Index(source[j:upper], emojiWordDelim)
|
nextWordDelim := bytes.Index(source[j:upper], emojiWordDelim)
|
||||||
|
|
||||||
if endEmoji < 0 {
|
if endEmoji < 0 {
|
||||||
start += upper + 1
|
start += 1
|
||||||
} else if endEmoji == 0 || (nextWordDelim != -1 && nextWordDelim < endEmoji) {
|
} else if endEmoji == 0 || (nextWordDelim != -1 && nextWordDelim < endEmoji) {
|
||||||
start += endEmoji + 1
|
start += endEmoji + 1
|
||||||
} else {
|
} else {
|
||||||
@@ -76,7 +75,6 @@ func Emojify(source []byte) []byte {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return source
|
return source
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func initEmoji() {
|
func initEmoji() {
|
||||||
|
@@ -53,12 +53,17 @@ func TestEmojiCustom(t *testing.T) {
|
|||||||
|
|
||||||
🍺`)},
|
🍺`)},
|
||||||
{"test :\n```bash\nthis is a test\n```\n\ntest\n\n:cool::blush:::pizza:\\:blush : : blush: :pizza:", []byte("test :\n```bash\nthis is a test\n```\n\ntest\n\n🆒😊:🍕\\:blush : : blush: 🍕")},
|
{"test :\n```bash\nthis is a test\n```\n\ntest\n\n:cool::blush:::pizza:\\:blush : : blush: :pizza:", []byte("test :\n```bash\nthis is a test\n```\n\ntest\n\n🆒😊:🍕\\:blush : : blush: 🍕")},
|
||||||
|
{
|
||||||
|
// 2391
|
||||||
|
"[a](http://gohugo.io) :smile: [r](http://gohugo.io/introduction/overview/) :beer:",
|
||||||
|
[]byte(`[a](http://gohugo.io) 😄 [r](http://gohugo.io/introduction/overview/) 🍺`),
|
||||||
|
},
|
||||||
} {
|
} {
|
||||||
|
|
||||||
result := Emojify([]byte(this.input))
|
result := Emojify([]byte(this.input))
|
||||||
|
|
||||||
if !reflect.DeepEqual(result, this.expect) {
|
if !reflect.DeepEqual(result, this.expect) {
|
||||||
t.Errorf("[%d] got '%q' but expected %q", i, result, this.expect)
|
t.Errorf("[%d] got %q but expected %q", i, result, this.expect)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user