Skip to content

Commit

Permalink
fix: Ignore emoji shorthand codes in URIs
Browse files Browse the repository at this point in the history
  • Loading branch information
socsieng committed Jul 30, 2022
1 parent 682bf96 commit 21aec01
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/core/render/emojify.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ export function emojify(text, useNativeEmoji) {
)
// Mark colons in comments
.replace(/<!--[\s\S]+?-->/g, m => m.replace(/:/g, '__colon__'))
// Mark colons in URIs
.replace(/[a-z]{2,}:\/\/[^\s]+/gi, m => m.replace(/:/g, '__colon__'))
// Replace emoji shorthand codes
.replace(/:([a-z0-9_\-+]+?):/g, (m, $1) =>
replaceEmojiShorthand(m, $1, useNativeEmoji)
Expand Down
2 changes: 2 additions & 0 deletions test/integration/__snapshots__/emoji.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

exports[`Emoji Ignores all emoji shorthand codes (noEmoji:true) 1`] = `"<p>:smile:</p><p>:smile::smile:</p><p>:smile: :smile:</p><p>:smile::smile::smile:</p><p>:smile: :smile: :smile:</p><p>text:smile:</p><p>:smile:text</p><p>text:smile:text</p>"`;

exports[`Emoji Ignores emoji shorthand codes in URIs 1`] = `"<p>Url <a href=\\"https://docsify.js.org/:foo:/\\" target=\\"_blank\\" rel=\\"noopener\\">https://docsify.js.org/:foo:/</a> <a href=\\"http://docsify.js.org/:100:/\\" target=\\"_blank\\" rel=\\"noopener\\">http://docsify.js.org/:100:/</a> <a href=\\"ftp://docsify.js.org/:smile:/\\" target=\\"_blank\\" rel=\\"noopener\\">ftp://docsify.js.org/:smile:/</a></p>"`;
exports[`Emoji Ignores emoji shorthand codes in code, pre, script, and template tags 1`] = `
"<pre>:100:</pre>
Expand Down
14 changes: 14 additions & 0 deletions test/integration/emoji.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,20 @@ describe('Emoji', function () {
expect(mainElm.innerHTML).toMatchSnapshot();
});

test('Ignores emoji shorthand codes in URIs', async () => {
await docsifyInit({
markdown: {
homepage:
'Url https://docsify.js.org/:foo:/ http://docsify.js.org/:100:/ ftp://docsify.js.org/:smile:/',
},
// _logHTML: true,
});

const mainElm = document.querySelector('#main');

expect(mainElm.innerHTML).toMatchSnapshot();
});

test('Ignores emoji shorthand codes in code, pre, script, and template tags', async () => {
await docsifyInit({
markdown: {
Expand Down

0 comments on commit 21aec01

Please sign in to comment.