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)
];

// These are regular expressions used to determine if a given Markdown heading
Expand Down
14 changes: 12 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 Expand Up @@ -80,6 +80,16 @@ describe('slug', () => {
});
});

describe('cli flag anchor preservation', () => {
it('preserves -- prefix for CLI flags', () => {
assert.strictEqual(slug('--permission', identity), '--permission');
});

it('preserves -- prefix for multi-word CLI flags', () => {
assert.strictEqual(slug('--allow-fs-read', identity), '--allow-fs-read');
});
});

describe('integration with github-slugger', () => {
it('lowercases and hyphenates a plain title', () => {
assert.strictEqual(slug('Hello World'), 'hello-world');
Expand Down
Loading