-
-
Notifications
You must be signed in to change notification settings - Fork 5.8k
Support unicode emojis and remove emojify.js #11032
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
Merged
Merged
Changes from all commits
Commits
Show all changes
99 commits
Select commit
Hold shift + click to select a range
d579c50
Support unicode emojis and remove emojify.js
mrsdizzie fe2bc47
add new shared function emojiHTML
silverwind 0ede4e7
don't increase emoji size in issue title
silverwind 6b2ce48
Update templates/repo/issue/view_content/add_reaction.tmpl
silverwind 5a91f51
Support for emoji rendering in various templates
mrsdizzie 4fd041c
Render code and review comments as they should be
mrsdizzie 08c508e
Better way to handle mail subjects
mrsdizzie 7c7c4e5
fix lint
mrsdizzie 3224944
insert unicode from tribute selection
silverwind 5c53378
Add template helper for plain text when needed
mrsdizzie f512e1a
small refactor
silverwind 6a6705f
Use existing replace function I forgot about
mrsdizzie 337d44f
Don't include emoji greater than Unicode Version 12
mrsdizzie bdd6aea
Fix regex
mrsdizzie 6393a91
Update build/generate-emoji.go
lafriks 7879f7c
Tweak regex slightly to really match everything including random invi…
mrsdizzie c2bed68
final updates
mrsdizzie d9ad9fc
last test fix
mrsdizzie f416214
code review
mrsdizzie 4618afc
code review
mrsdizzie b4ca18b
hard code gitea custom emoji to match previous behavior
mrsdizzie 40787b4
Merge branch 'master' into emoji
guillep2k 57d4c5d
Merge branch 'master' into emoji
lafriks ebfb65e
Merge branch 'master' into emoji
lafriks 17dfefc
Merge branch 'master' into emoji
lafriks d989ee7
Merge branch 'master' into emoji
mrsdizzie 3ce33c7
Merge branch 'master' into emoji
guillep2k ff80057
test trying to add these files back
mrsdizzie e4793de
Merge branch 'master' into emoji
mrsdizzie 77a41ec
attempt to remove useless frontend builds
silverwind 9f6b7b4
Revert "attempt to remove useless frontend builds"
silverwind eb9c9c2
Add some debugging code to test if disk write being limited during tests
mrsdizzie 4f0092d
more debugging
mrsdizzie b6ad60c
more debugging try to limit what drone does while testing
mrsdizzie 673f31d
drone fix
mrsdizzie 6b1123c
remove dep
mrsdizzie d6d0c02
try one more time
mrsdizzie 2008ef4
fix
mrsdizzie db6bf37
yet more debugging
mrsdizzie f7e9e60
typo
mrsdizzie d62518b
drone testing
mrsdizzie 41beece
typo
mrsdizzie 8f0628f
revert debugging changes
mrsdizzie 9c081af
change from master that got lost in rebases
mrsdizzie 2b4bfa4
Merge branch 'master' into emoji
mrsdizzie 147f226
formatting error
mrsdizzie 0153bd2
Merge branch 'master' into emoji
mrsdizzie 0304aee
Update .eslintrc
mrsdizzie e18f275
Merge branch 'master' into emoji
mrsdizzie 49dfdcc
another debugging attempt
mrsdizzie c00a209
better way to track slow time
mrsdizzie d1755cb
remove debugging of debugging
mrsdizzie 4264061
lint
mrsdizzie af89bc1
expand to push command
mrsdizzie 00d5ba2
add hook logging
mrsdizzie 0a9804e
Merge branch 'master' into emoji
mrsdizzie a33d6d1
one more
mrsdizzie 81e28d2
get a better idea if gitea is really exiting after running hook
mrsdizzie 0fb103a
Merge branch 'master' into emoji
mrsdizzie a0038cc
fmt
mrsdizzie 65f7595
revert last change it doesn't work as it does on my machine
mrsdizzie 16571c2
try different way to get time
mrsdizzie 9bfaf86
more logging
mrsdizzie 8adbbe7
more log
mrsdizzie bc43a5f
time init
mrsdizzie 6b46b8c
trace all init calls
mrsdizzie c56b526
not these
mrsdizzie 92af022
almost
mrsdizzie 4d1cd05
less logging
mrsdizzie 952ee78
debug
mrsdizzie 36cd227
debug
mrsdizzie 6fff0dd
drone
mrsdizzie f0d6c16
drone
mrsdizzie 1e25d2f
more init log
mrsdizzie 2b36fc0
less logging
mrsdizzie 51017ab
debug
mrsdizzie 2d369fa
debug
mrsdizzie 54e1a8c
undo last change it was not that
mrsdizzie a55332b
strace
mrsdizzie acc19ec
trace all hooks
mrsdizzie 0ef92ba
more trace
mrsdizzie c5c13ac
see if related to preemptive scheduling
mrsdizzie 4b9e43c
lint
mrsdizzie 7cd7afe
goproxy
mrsdizzie 608e5ca
remove emoji init
mrsdizzie 252787b
try again
mrsdizzie 2490f18
fmt
mrsdizzie d31d7bd
really fix lint
mrsdizzie d4c9b75
remove some debugging code
mrsdizzie 0c58b15
more cleanup
mrsdizzie 144c78e
Merge branch 'master' into emoji
mrsdizzie 080f5e6
different logging
mrsdizzie 53e3abb
disable preempt
mrsdizzie 8317565
more debug undoing
mrsdizzie cf1ec0e
Merge branch 'master' into emoji
mrsdizzie 24545a7
more cleanup
mrsdizzie 9ebb307
Merge branch 'master' into emoji
mrsdizzie 3473119
delete all emojify files
mrsdizzie 82caeb3
ci
mrsdizzie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,184 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Copyright 2015 Kenneth Shaw | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
// +build ignore | ||
|
||
package main | ||
|
||
import ( | ||
"encoding/json" | ||
"flag" | ||
"fmt" | ||
"go/format" | ||
"io/ioutil" | ||
"log" | ||
"net/http" | ||
"regexp" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
) | ||
|
||
const ( | ||
gemojiURL = "https://raw.githubusercontent.com/github/gemoji/master/db/emoji.json" | ||
maxUnicodeVersion = 12 | ||
) | ||
|
||
var ( | ||
flagOut = flag.String("o", "modules/emoji/emoji_data.go", "out") | ||
) | ||
|
||
// Gemoji is a set of emoji data. | ||
type Gemoji []Emoji | ||
|
||
// Emoji represents a single emoji and associated data. | ||
type Emoji struct { | ||
Emoji string `json:"emoji"` | ||
Description string `json:"description,omitempty"` | ||
Aliases []string `json:"aliases"` | ||
UnicodeVersion string `json:"unicode_version,omitempty"` | ||
} | ||
|
||
// Don't include some fields in JSON | ||
func (e Emoji) MarshalJSON() ([]byte, error) { | ||
type emoji Emoji | ||
x := emoji(e) | ||
x.UnicodeVersion = "" | ||
x.Description = "" | ||
return json.Marshal(x) | ||
} | ||
|
||
func main() { | ||
var err error | ||
|
||
flag.Parse() | ||
|
||
// generate data | ||
buf, err := generate() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
// write | ||
err = ioutil.WriteFile(*flagOut, buf, 0644) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
} | ||
|
||
var replacer = strings.NewReplacer( | ||
"main.Gemoji", "Gemoji", | ||
"main.Emoji", "\n", | ||
"}}", "},\n}", | ||
", Description:", ", ", | ||
", Aliases:", ", ", | ||
", UnicodeVersion:", ", ", | ||
) | ||
|
||
var emojiRE = regexp.MustCompile(`\{Emoji:"([^"]*)"`) | ||
|
||
func generate() ([]byte, error) { | ||
var err error | ||
|
||
// load gemoji data | ||
res, err := http.Get(gemojiURL) | ||
if err != nil { | ||
return nil, err | ||
} | ||
defer res.Body.Close() | ||
|
||
// read all | ||
body, err := ioutil.ReadAll(res.Body) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
// unmarshal | ||
var data Gemoji | ||
err = json.Unmarshal(body, &data) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
var re = regexp.MustCompile(`keycap|registered|copyright`) | ||
tmp := data[:0] | ||
|
||
// filter out emoji that require greater than max unicode version | ||
for i := range data { | ||
val, _ := strconv.ParseFloat(data[i].UnicodeVersion, 64) | ||
if int(val) <= maxUnicodeVersion { | ||
// remove these keycaps for now they really complicate matching since | ||
// they include normal letters in them | ||
if re.MatchString(data[i].Description) { | ||
continue | ||
} | ||
tmp = append(tmp, data[i]) | ||
} | ||
} | ||
data = tmp | ||
|
||
sort.Slice(data, func(i, j int) bool { | ||
return data[i].Aliases[0] < data[j].Aliases[0] | ||
}) | ||
|
||
aliasPairs := make([]string, 0) | ||
aliasMap := make(map[string]int, len(data)) | ||
|
||
for i, e := range data { | ||
if e.Emoji == "" || len(e.Aliases) == 0 { | ||
continue | ||
} | ||
for _, a := range e.Aliases { | ||
if a == "" { | ||
continue | ||
} | ||
aliasMap[a] = i | ||
aliasPairs = append(aliasPairs, ":"+a+":", e.Emoji) | ||
} | ||
} | ||
|
||
// gitea customizations | ||
i, ok := aliasMap["tada"] | ||
if ok { | ||
data[i].Aliases = append(data[i].Aliases, "hooray") | ||
} | ||
i, ok = aliasMap["laughing"] | ||
if ok { | ||
data[i].Aliases = append(data[i].Aliases, "laugh") | ||
} | ||
|
||
// add header | ||
str := replacer.Replace(fmt.Sprintf(hdr, gemojiURL, data)) | ||
|
||
// change the format of the unicode string | ||
str = emojiRE.ReplaceAllStringFunc(str, func(s string) string { | ||
var err error | ||
s, err = strconv.Unquote(s[len("{Emoji:"):]) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return "{" + strconv.QuoteToASCII(s) | ||
}) | ||
|
||
// write a JSON file to use with tribute | ||
file, _ := json.Marshal(data) | ||
_ = ioutil.WriteFile("assets/emoji.json", file, 0644) | ||
|
||
// format | ||
return format.Source([]byte(str)) | ||
} | ||
|
||
const hdr = ` | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package emoji | ||
|
||
// Code generated by gen.go. DO NOT EDIT. | ||
// Sourced from %s | ||
// | ||
var GemojiData = %#v | ||
` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
// Copyright 2020 The Gitea Authors. All rights reserved. | ||
// Copyright 2015 Kenneth Shaw | ||
// Use of this source code is governed by a MIT-style | ||
// license that can be found in the LICENSE file. | ||
|
||
package emoji | ||
|
||
import ( | ||
"strings" | ||
"sync" | ||
) | ||
|
||
// Gemoji is a set of emoji data. | ||
type Gemoji []Emoji | ||
|
||
// Emoji represents a single emoji and associated data. | ||
type Emoji struct { | ||
Emoji string | ||
Description string | ||
Aliases []string | ||
UnicodeVersion string | ||
} | ||
|
||
var ( | ||
// codeMap provides a map of the emoji unicode code to its emoji data. | ||
codeMap map[string]int | ||
|
||
// aliasMap provides a map of the alias to its emoji data. | ||
aliasMap map[string]int | ||
|
||
// codeReplacer is the string replacer for emoji codes. | ||
codeReplacer *strings.Replacer | ||
|
||
// aliasReplacer is the string replacer for emoji aliases. | ||
aliasReplacer *strings.Replacer | ||
|
||
once sync.Once | ||
) | ||
|
||
func loadMap() { | ||
|
||
once.Do(func() { | ||
|
||
// initialize | ||
codeMap = make(map[string]int, len(GemojiData)) | ||
aliasMap = make(map[string]int, len(GemojiData)) | ||
|
||
// process emoji codes and aliases | ||
codePairs := make([]string, 0) | ||
aliasPairs := make([]string, 0) | ||
for i, e := range GemojiData { | ||
if e.Emoji == "" || len(e.Aliases) == 0 { | ||
continue | ||
} | ||
|
||
// setup codes | ||
codeMap[e.Emoji] = i | ||
codePairs = append(codePairs, e.Emoji, ":"+e.Aliases[0]+":") | ||
|
||
// setup aliases | ||
for _, a := range e.Aliases { | ||
if a == "" { | ||
continue | ||
} | ||
|
||
aliasMap[a] = i | ||
aliasPairs = append(aliasPairs, ":"+a+":", e.Emoji) | ||
} | ||
} | ||
|
||
// create replacers | ||
codeReplacer = strings.NewReplacer(codePairs...) | ||
aliasReplacer = strings.NewReplacer(aliasPairs...) | ||
}) | ||
} | ||
|
||
// FromCode retrieves the emoji data based on the provided unicode code (ie, | ||
// "\u2618" will return the Gemoji data for "shamrock"). | ||
func FromCode(code string) *Emoji { | ||
loadMap() | ||
i, ok := codeMap[code] | ||
if !ok { | ||
return nil | ||
} | ||
|
||
return &GemojiData[i] | ||
} | ||
|
||
// FromAlias retrieves the emoji data based on the provided alias in the form | ||
// "alias" or ":alias:" (ie, "shamrock" or ":shamrock:" will return the Gemoji | ||
// data for "shamrock"). | ||
func FromAlias(alias string) *Emoji { | ||
loadMap() | ||
if strings.HasPrefix(alias, ":") && strings.HasSuffix(alias, ":") { | ||
alias = alias[1 : len(alias)-1] | ||
} | ||
|
||
i, ok := aliasMap[alias] | ||
if !ok { | ||
return nil | ||
} | ||
|
||
return &GemojiData[i] | ||
} | ||
|
||
// ReplaceCodes replaces all emoji codes with the first corresponding emoji | ||
// alias (in the form of ":alias:") (ie, "\u2618" will be converted to | ||
// ":shamrock:"). | ||
func ReplaceCodes(s string) string { | ||
loadMap() | ||
return codeReplacer.Replace(s) | ||
} | ||
|
||
// ReplaceAliases replaces all aliases of the form ":alias:" with its | ||
// corresponding unicode value. | ||
func ReplaceAliases(s string) string { | ||
loadMap() | ||
return aliasReplacer.Replace(s) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.