-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
feat: Native emoji w/ image-based fallbacks and improved parsing #1746
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
39 commits
Select commit
Hold shift + click to select a range
936d566
Render native emoji with image fallback
jhildenbiddle e7d627a
Deprecate emoji plugin
jhildenbiddle db1e94e
Add emoji tests
jhildenbiddle 1fa45e5
Remove console.log statement
jhildenbiddle 8252f3a
Fix emoji image alt attribute
jhildenbiddle b8c227f
Set nativeEmoji to false by default (non-breaking)
jhildenbiddle d03aa4f
Fix parsing emoji in HTML comments and script tags
jhildenbiddle 39d5204
Add nativeEmoji and update noEmoji details
jhildenbiddle baf8044
Add Emoji plugin deprecation notice
jhildenbiddle 39bf522
Fix ESLint issues
jhildenbiddle e1e8d22
Create build:emoji task
jhildenbiddle 8c10b5f
Fix rendering of GitHub emoji without unicode
jhildenbiddle 208049b
Adjust and match size of native and image emoji
jhildenbiddle b7a3b67
Update emoji test snapshot
jhildenbiddle 260992c
Update docs test snapshot
jhildenbiddle 2079441
Merge branch 'develop' into feat-native-emoji
Koooooo-7 8b587b8
Fix ci/codesandbox error
jhildenbiddle 53d5fb5
Update native emoji font-stack
jhildenbiddle e9d5722
Fix rendering of native multi-character emoji
jhildenbiddle 7c15fd7
Kick GitHub Workflow
jhildenbiddle 05c7974
Merge branch 'develop' into feat-native-emoji
jhildenbiddle 7ba8513
Replace rollup’s uglify plugin with terser
jhildenbiddle d52b476
Switch “npm ci” instead of “npm i” for stability
jhildenbiddle 3f2dd46
Change emoji data from default to named export
jhildenbiddle e06fed4
Revert "Replace rollup’s uglify plugin with terser"
jhildenbiddle 77cb0cd
Revert "Switch “npm ci” instead of “npm i” for stability"
jhildenbiddle 98185ca
Revert "Change emoji data from default to named export"
jhildenbiddle bec3e0d
Specify codesandbox template and node version
jhildenbiddle 16aec44
Update codesandbox config
jhildenbiddle 27d4952
Revert "Revert "Replace rollup’s uglify plugin with terser""
jhildenbiddle 4208c82
Revert "Revert "Revert "Replace rollup’s uglify plugin with terser"""
jhildenbiddle 5120dd2
Update codesandbox config
jhildenbiddle 8cdf27e
Revert "Update codesandbox config"
jhildenbiddle 9d522d5
Fix codesandbox uglify error
jhildenbiddle ddf7ad2
Emoji docs tweaks
jhildenbiddle da6480d
Restore and update emoji plugin code
jhildenbiddle 4a1d87e
Restore and update emoji plugin docs
jhildenbiddle d9fc279
Prettier updates
jhildenbiddle af45845
Match lowercase shortcodes only
jhildenbiddle File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
{ | ||
"sandboxes": ["2d17z"], | ||
"packages": [".", "packages/docsify-server-renderer"] | ||
"packages": [".", "packages/docsify-server-renderer"], | ||
"node": "16" | ||
} |
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,91 @@ | ||
const axios = require('axios'); | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
|
||
const filePaths = { | ||
emojiMarkdown: path.resolve(process.cwd(), 'docs', 'emoji.md'), | ||
emojiJS: path.resolve( | ||
process.cwd(), | ||
'src', | ||
'core', | ||
'render', | ||
'emojify-data.js' | ||
), | ||
}; | ||
|
||
async function getEmojiData() { | ||
const emojiDataURL = 'https://api.github.com/emojis'; | ||
const response = await axios.get(emojiDataURL); | ||
const baseURL = Object.values(response.data) | ||
.find(url => /unicode\//) | ||
.split('unicode/')[0]; | ||
const data = { ...response.data }; | ||
|
||
// Remove base URL from emoji URLs | ||
Object.entries(data).forEach( | ||
([key, value]) => (data[key] = value.replace(baseURL, '')) | ||
); | ||
|
||
return { | ||
baseURL, | ||
data, | ||
}; | ||
} | ||
|
||
function writeEmojiPage(emojiData) { | ||
const emojiPage = | ||
(fs.existsSync(filePaths.emojiMarkdown) && | ||
fs.readFileSync(filePaths.emojiMarkdown, 'utf8')) || | ||
`<!-- START -->\n\n<!-- END -->`; | ||
const emojiRegEx = /(<!--\s*START.*-->\n)([\s\S]*)(\n<!--\s*END.*-->)/; | ||
const emojiMatch = emojiPage.match(emojiRegEx); | ||
const emojiMarkdownStart = emojiMatch[1].trim(); | ||
const emojiMarkdown = emojiMatch[2].trim(); | ||
const emojiMarkdownEnd = emojiMatch[3].trim(); | ||
const newEmojiMarkdown = Object.keys(emojiData.data) | ||
.reduce( | ||
(preVal, curVal) => | ||
(preVal += `:${curVal}: ` + '`' + `:${curVal}:` + '`' + '\n\n'), | ||
'' | ||
) | ||
.trim(); | ||
|
||
if (emojiMarkdown !== newEmojiMarkdown) { | ||
const newEmojiPage = emojiPage.replace( | ||
emojiMatch[0], | ||
`${emojiMarkdownStart}\n${newEmojiMarkdown}\n${emojiMarkdownEnd}` | ||
); | ||
|
||
fs.writeFileSync(filePaths.emojiMarkdown, newEmojiPage); | ||
console.info(`- Created new file: ${filePaths.emojiMarkdown}`); | ||
} else { | ||
console.info(`- No changes to file: ${filePaths.emojiMarkdown}`); | ||
} | ||
} | ||
|
||
function writeEmojiJS(emojiData) { | ||
const emojiJS = | ||
fs.existsSync(filePaths.emojiJS) && | ||
fs.readFileSync(filePaths.emojiJS, 'utf8'); | ||
const newEmojiJS = `export default ${JSON.stringify(emojiData, {}, 2)}`; | ||
|
||
if (!emojiJS || emojiJS !== newEmojiJS) { | ||
fs.writeFileSync(filePaths.emojiJS, newEmojiJS); | ||
console.info(`- Created new file: ${filePaths.emojiJS}`); | ||
} else { | ||
console.info(`- No changes to file: ${filePaths.emojiJS}`); | ||
} | ||
} | ||
|
||
(async () => { | ||
console.log('Build emoji'); | ||
|
||
try { | ||
const emojiData = await getEmojiData(); | ||
|
||
writeEmojiPage(emojiData); | ||
writeEmojiJS(emojiData); | ||
} catch (e) { | ||
console.error(e); | ||
} | ||
})(); |
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
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.