Skip to content

Commit 946564c

Browse files
authored
fix(slugger): optimize trailing/leading regex (#610)
* fix(slugger): optimize trailing/leading regex * fixup! * fixup! * fixup!
1 parent 0b29712 commit 946564c

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/utils/parser/constants.mjs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@ export const DOC_API_SLUGS_REPLACEMENTS = [
55
{ from: /node.js/i, to: 'nodejs' }, // Replace Node.js
66
{ from: /&/, to: '-and-' }, // Replace &
77
{ from: /[/_,:;\\ ]/g, to: '-' }, // Replace /_,:;\. and whitespace
8-
{ from: /--+/g, to: '-' }, // Replace multiple hyphens with single
9-
{ from: /^-/, to: '' }, // Remove any leading hyphen
10-
{ from: /-$/, to: '' }, // Remove any trailing hyphen
8+
{ from: /^-+(?!-*$)/g, to: '' }, // Remove any leading hyphens
9+
{ from: /(?<!^-*)-+$/g, to: '' }, // Remove any trailing hyphens
10+
{ from: /^(?!-+$).*?(--+)/g, to: '-' }, // Replace multiple hyphens
1111
];
1212

1313
// This is the base URL of the MDN Web documentation

0 commit comments

Comments
 (0)