Skip to content

Commit 1438a94

Browse files
committed
metadata: preserve CLI flag anchors
Signed-off-by: Herrtian <70463940+Herrtian@users.noreply.github.com>
1 parent f97991b commit 1438a94

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

src/generators/metadata/constants.mjs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export const DOC_API_SLUGS_REPLACEMENTS = [
1111
{ from: /node.js/i, to: 'nodejs' }, // Replace Node.js
1212
{ from: /&/, to: '-and-' }, // Replace &
1313
{ from: /[/,:;\\ ]/g, to: '-' }, // Replace /,:;\. and whitespace
14-
{ from: /^-+(?!-*$)/g, to: '' }, // Remove any leading hyphens
14+
{ from: /^-(?!-|$)/g, to: '' }, // Remove a single leading hyphen
1515
{ from: /(?<!^-*)-+$/g, to: '' }, // Remove any trailing hyphens
16-
{ from: /^(?!-+$).*?(--+)/g, to: '-' }, // Replace multiple hyphens
16+
{ from: /^(?!-)(?!-+$).*?(--+)/g, to: '-' }, // Replace multiple hyphens
1717
];
1818

1919
// These are regular expressions used to determine if a given Markdown heading

src/generators/metadata/utils/__tests__/slugger.test.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,8 @@ describe('slug', () => {
5151
assert.strictEqual(slug('-foo', identity), 'foo');
5252
});
5353

54-
it('removes multiple leading hyphens', () => {
55-
assert.strictEqual(slug('--foo', identity), 'foo');
54+
it('preserves multiple leading hyphens', () => {
55+
assert.strictEqual(slug('--permission', identity), '--permission');
5656
});
5757

5858
it('preserves an all-hyphen string', () => {
@@ -78,6 +78,10 @@ describe('slug', () => {
7878
it('does not fire on an all-hyphen string', () => {
7979
assert.strictEqual(slug('---', identity), '---');
8080
});
81+
82+
it('does not collapse leading double hyphen flags', () => {
83+
assert.strictEqual(slug('--allow-fs-read', identity), '--allow-fs-read');
84+
});
8185
});
8286

8387
describe('integration with github-slugger', () => {

0 commit comments

Comments
 (0)