From ccce32b3d911fdc9a40330e33835918e60d640ee Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sun, 14 Dec 2025 00:38:21 +1100 Subject: [PATCH 1/3] Fix regex to escape additional characters in header --- anchor-markdown-header.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/anchor-markdown-header.js b/anchor-markdown-header.js index 7993a73..ce88176 100644 --- a/anchor-markdown-header.js +++ b/anchor-markdown-header.js @@ -23,7 +23,7 @@ function basicGithubId(text) { // escape codes .replace(/%([abcdef]|\d){2,2}/ig, '') // single chars that are removed - .replace(/[\/?!:\[\]`.,()*"';{}+=<>~\$|#@&–—]/g,'') + .replace(/[\/\\?!%:\[\]`.,()*"';{}+=<>~\$|#@&–—]/g,'') // CJK punctuations that are removed .replace(/[。?!,、;:“”【】()〔〕[]﹃﹄“ ”‘’﹁﹂—…-~《》〈〉「」]/g, '') ; From b418b3fa91d9aa86414dbed6ed6df20ee65657e3 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sun, 14 Dec 2025 00:43:05 +1100 Subject: [PATCH 2/3] Add test cases for percentage and back slash --- test/anchor-markdown-header.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/test/anchor-markdown-header.js b/test/anchor-markdown-header.js index 5bb62cc..0ecd514 100644 --- a/test/anchor-markdown-header.js +++ b/test/anchor-markdown-header.js @@ -76,6 +76,8 @@ test('\ngenerating anchor in github mode', function (t) { , [ 'bar_foo', null, '#bar_foo'] , [ 'baz_foo_', null, '#baz_foo_'] , [ '_foo_bax_', null, '#foo_bax'] + , [ '10% off', null, '#10-off'] + , [ '1/2 affected', null, '#12-affected'] ].forEach(function (x) { check(x[0], x[1], x[2]) }); t.end(); From 9f567fda7aafb410250c1be5d9d9af1bc1658882 Mon Sep 17 00:00:00 2001 From: James Thompson Date: Sun, 14 Dec 2025 12:42:37 +1100 Subject: [PATCH 3/3] Add latin 1 chars that are removed --- anchor-markdown-header.js | 3 +++ test/anchor-markdown-header.js | 1 + 2 files changed, 4 insertions(+) diff --git a/anchor-markdown-header.js b/anchor-markdown-header.js index ce88176..4339297 100644 --- a/anchor-markdown-header.js +++ b/anchor-markdown-header.js @@ -26,6 +26,8 @@ function basicGithubId(text) { .replace(/[\/\\?!%:\[\]`.,()*"';{}+=<>~\$|#@&–—]/g,'') // CJK punctuations that are removed .replace(/[。?!,、;:“”【】()〔〕[]﹃﹄“ ”‘’﹁﹂—…-~《》〈〉「」]/g, '') + // latin-1 supplement chars that are removed + .replace(/[¡¢£¤¥¦§¨©«¬®¯±²³´¶·¸¹º»¼½¾¿]/g, '') ; } @@ -91,6 +93,7 @@ function getGitlabId(text, repetition) { .replace(/\s+/g, '-') // All spaces are converted to hyphens .replace(/[\/?!:\[\]`.,()*"';{}+=<>~\$|#@]/g,'') // All non-word text (e.g., punctuation, HTML) is removed .replace(/[。?!,、;:“”【】()〔〕[]﹃﹄“ ”‘’﹁﹂—…-~《》〈〉「」]/g, '') // remove CJK punctuations + .replace(/[¹²³]/g, '') // remove snall subset of latin-1 supplement chars .replace(/[-]+/g,'-') // duplicated hyphen .replace(/^-/,'') // ltrim hyphen .replace(/-$/,''); // rtrim hyphen diff --git a/test/anchor-markdown-header.js b/test/anchor-markdown-header.js index 0ecd514..788cb6d 100644 --- a/test/anchor-markdown-header.js +++ b/test/anchor-markdown-header.js @@ -78,6 +78,7 @@ test('\ngenerating anchor in github mode', function (t) { , [ '_foo_bax_', null, '#foo_bax'] , [ '10% off', null, '#10-off'] , [ '1/2 affected', null, '#12-affected'] + , [ '¡¢£¤¥¦§¨©ª«¬®¯°±²³´µ¶·¸¹º»¼½¾¿Latin 1', null, '#%C2%AA%C2%B0%C2%B5latin-1'] ].forEach(function (x) { check(x[0], x[1], x[2]) }); t.end();