Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/generators/metadata/constants.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const DOC_API_SLUGS_REPLACEMENTS = [
{ from: /node.js/i, to: 'nodejs' }, // Replace Node.js
{ from: /&/, to: '-and-' }, // Replace &
{ from: /[/,:;\\ ]/g, to: '-' }, // Replace /,:;\. and whitespace
{ from: /^-+(?!-*$)/g, to: '' }, // Remove any leading hyphens
{ from: /^-(?=[^-])/g, to: '' }, // Remove a single leading hyphen (preserves -- prefix for CLI flags)
{ from: /(?<!^-*)-+$/g, to: '' }, // Remove any trailing hyphens
{ from: /^(?!-+$).*?(--+)/g, to: '-' }, // Replace multiple hyphens
{ from: /^(?!-+$)[^-].*?(--+)/g, to: '-' }, // Replace multiple consecutive hyphens (not at start)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This regex looks very odd, unless there is some magic going on, this is replacing all of [^-].*?(--+) with -?

];

// These are regular expressions used to determine if a given Markdown heading
Expand Down
4 changes: 2 additions & 2 deletions src/generators/metadata/utils/__tests__/slugger.test.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ describe('slug', () => {
assert.strictEqual(slug('-foo', identity), 'foo');
});

it('removes multiple leading hyphens', () => {
assert.strictEqual(slug('--foo', identity), 'foo');
it('preserves double leading hyphens (CLI flag prefix)', () => {
assert.strictEqual(slug('--foo', identity), '--foo');
});

it('preserves an all-hyphen string', () => {
Expand Down
Loading