Add emoji support

This uses the Emoji map from https://github.com/kyokomi/emoji -- but with a custom replacement implementation.

The built-in are fine for most use cases, but in Hugo we do care about pure speed.

The benchmarks below are skewed in Hugo's direction as the source and result is a byte slice,
Kyokomi's implementation works best with strings.

Curious: The easy-to-use `strings.Replacer` is also plenty fast.

```
BenchmarkEmojiKyokomiFprint-4  	   20000	     86038 ns/op	   33960 B/op	     117 allocs/op
BenchmarkEmojiKyokomiSprint-4  	   20000	     83252 ns/op	   38232 B/op	     122 allocs/op
BenchmarkEmojiStringsReplacer-4	  100000	     21092 ns/op	   17248 B/op	      25 allocs/op
BenchmarkHugoEmoji-4           	  500000	      5728 ns/op	     624 B/op	      13 allocs/op
```

Fixes #1891
This commit is contained in:
Bjørn Erik Pedersen
2016-02-25 00:52:11 +01:00
committed by Cameron Moore
parent 5926c6c8d5
commit cafb784799
7 changed files with 256 additions and 3 deletions

View File

@@ -99,6 +99,9 @@ Following is a list of Hugo-defined variables that you can configure and their c
disableRobotsTXT: false
# edit new content with this editor, if provided
editor: ""
# Enable Emoji emoticons support for page content.
# See www.emoji-cheat-sheet.com
enableEmoji: false
footnoteAnchorPrefix: ""
footnoteReturnLinkContents: ""
# google analytics tracking id

View File

@@ -413,6 +413,14 @@ These are formatted with the layout string.
e.g. `{{ dateFormat "Monday, Jan 2, 2006" "2015-01-21" }}` → "Wednesday, Jan 21, 2015"
### emojify
Runs the string through the Emoji emoticons processor. The result will be declared as "safe" so Go templates will not filter it.
See the [Emoji cheat sheet](http://www.emoji-cheat-sheet.com/) for available emoticons.
e.g. `{{ "I :heart: Hugo" | emojify }}`
### highlight
Takes a string of code and a language, uses Pygments to return the syntax highlighted code in HTML.
Used in the [highlight shortcode](/extras/highlighting/).