From ee7536fc14a68e1db1887b9d6dc10095f19cf573 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marc=20Cornell=C3=A0?= Date: Wed, 23 Sep 2020 12:24:57 +0200 Subject: [PATCH] Preserve %EF%B8%8F in GitHub anchors Fixes #36 --- .gitignore | 1 + anchor-markdown-header.js | 4 ++-- test/anchor-markdown-header.js | 4 +++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index de78e27..bb46726 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ results node_modules npm-debug.log tmp +package-lock.json diff --git a/anchor-markdown-header.js b/anchor-markdown-header.js index 764d477..29e7531 100644 --- a/anchor-markdown-header.js +++ b/anchor-markdown-header.js @@ -38,7 +38,7 @@ function getGithubId(text, repetition) { } // Strip emojis - text = text.replace(emojiRegex(), '') + text = text.replace(emojiRegex(), ''); return text; } @@ -123,7 +123,7 @@ module.exports = function anchorMarkdownHeader(header, mode, repetition, moduleN // encodeURI replaces the zero width joiner character // (used to generate emoji sequences, e.g.Female Construction Worker 👷🏼‍♀️) // github doesn't URL encode them, so we replace them after url encoding to preserve the zwj character. - return newURI.replace(/%E2%80%8D/g, '\u200D'); + return newURI.replace(/%E2%80%8D/g, '%EF%B8%8F'); }; break; case 'bitbucket.org': diff --git a/test/anchor-markdown-header.js b/test/anchor-markdown-header.js index 9aef11d..895e934 100644 --- a/test/anchor-markdown-header.js +++ b/test/anchor-markdown-header.js @@ -46,7 +46,9 @@ test('\ngenerating anchor in github mode', function (t) { , [ 'Modules 📦', null, '#modules-'] , [ 'Modu📦les', null, '#modules'] , [ 'Mo📦du📦les', null, '#modules'] - , [ '👷🏼‍♀️ Maintenance', null, '#\u200D-maintenance'] + , [ '👷🏼‍♀️ Maintenance', null, '#%EF%B8%8F-maintenance'] + , [ 'Alarm clock ⏰', null, '#alarm-clock-'] + , [ 'Apple Watch ⌚️', null, '#apple-watch-%EF%B8%8F'] ].forEach(function (x) { check(x[0], x[1], x[2]) }); t.end(); })