Skip to content

Commit 2765300

Browse files
fix(metadata): preserve underscores in generated anchor IDs (#749)
The DOC_API_SLUGS_REPLACEMENTS regex was converting underscores to dashes, breaking internal links across the Node.js docs
1 parent b2330d9 commit 2765300

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

src/generators/metadata/constants.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ export const IGNORE_STABILITY_STEMS = ['documentation'];
66
export const DOC_API_SLUGS_REPLACEMENTS = [
77
{ from: /node.js/i, to: 'nodejs' }, // Replace Node.js
88
{ from: /&/, to: '-and-' }, // Replace &
9-
{ from: /[/_,:;\\ ]/g, to: '-' }, // Replace /_,:;\. and whitespace
9+
{ from: /[/,:;\\ ]/g, to: '-' }, // Replace /,:;\. and whitespace
1010
{ from: /^-+(?!-*$)/g, to: '' }, // Remove any leading hyphens
1111
{ from: /(?<!^-*)-+$/g, to: '' }, // Remove any trailing hyphens
1212
{ from: /^(?!-+$).*?(--+)/g, to: '-' }, // Replace multiple hyphens

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,8 @@ describe('slug', () => {
2525
});
2626

2727
describe('special character to hyphen replacement', () => {
28-
it('replaces underscores with hyphens', () => {
29-
assert.strictEqual(slug('foo_bar', identity), 'foo-bar');
28+
it('preserves underscores', () => {
29+
assert.strictEqual(slug('foo_bar', identity), 'foo_bar');
3030
});
3131

3232
it('replaces forward slashes with hyphens', () => {
@@ -85,8 +85,8 @@ describe('slug', () => {
8585
assert.strictEqual(slug('Hello World'), 'hello-world');
8686
});
8787

88-
it('converts underscored names to hyphenated slugs', () => {
89-
assert.strictEqual(slug('child_process'), 'child-process');
88+
it('preserves underscores in module names', () => {
89+
assert.strictEqual(slug('child_process'), 'child_process');
9090
});
9191

9292
it('handles titles with no special characters', () => {

0 commit comments

Comments
 (0)