-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #985 from pxgo/master
优化,调整,修复
- Loading branch information
Showing
1,687 changed files
with
13,129 additions
and
5,107 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,41 @@ | ||
const fluentuiEmoji = require('./fluentuiEmoji.json'); | ||
const emojiRegex = require('emoji-regex'); | ||
const regex = (emojiRegex.default || emojiRegex)(); | ||
const fluentuiEmojiUnicode = []; | ||
const fluentuiEmoji_unicode_emoji = {}; | ||
const fluentuiEmoji_char_emoji = {}; | ||
|
||
for (const group of fluentuiEmoji) { | ||
for (const emoji of group.emoji) { | ||
fluentuiEmojiUnicode.push(emoji.unicode); | ||
fluentuiEmoji_unicode_emoji[emoji.unicode] = emoji; | ||
fluentuiEmoji_char_emoji[emoji.glyph] = emoji; | ||
} | ||
} | ||
|
||
function replaceEmojiWithImgTags(htmlString = '') { | ||
const { getUrl } = require('./tools'); | ||
return htmlString.replace(regex, (char) => { | ||
const emoji = fluentuiEmoji_char_emoji[char]; | ||
if (!emoji) { | ||
return char; | ||
} | ||
const emojiUrl = getUrl('emoji', emoji.unicode); | ||
return `<img src="${emojiUrl}" class="emoji" data-tag="nkcsource" data-type="twemoji" alt="${char}">`; | ||
}); | ||
} | ||
|
||
function getEmojiCharByUnicode(unicode) { | ||
const emoji = fluentuiEmoji_unicode_emoji[unicode]; | ||
if (!emoji) { | ||
return '?'; | ||
} | ||
return emoji.glyph; | ||
} | ||
|
||
module.exports = { | ||
fluentuiEmojiUnicode, | ||
fluentuiEmoji, | ||
replaceEmojiWithImgTags, | ||
getEmojiCharByUnicode, | ||
}; |
Oops, something went wrong.