Skip to content

Commit 6f19b18

Browse files
authored
fix: use DEP code as slug for deprecation headings (#752)
1 parent 8a9bb3b commit 6f19b18

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
'use strict';
2+
3+
// Matches deprecation headings (e.g., "DEP0001: some title") and captures
4+
// the deprecation code (e.g., "DEP0001") as the first group
5+
export const DEPRECATION_HEADING_REGEX = /^(DEP\d+):/;

src/generators/legacy-html/utils/__tests__/slugger.test.mjs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,4 +36,28 @@ describe('createLegacySlugger', () => {
3636
assert.strictEqual(getLegacySlug('Hello', 'fs'), 'fs_hello_2');
3737
assert.strictEqual(getLegacySlug('World', 'fs'), 'fs_world');
3838
});
39+
40+
describe('deprecation headings', () => {
41+
it('returns the DEP code for a deprecation heading', () => {
42+
const getLegacySlug = createLegacySlugger();
43+
assert.strictEqual(
44+
getLegacySlug(
45+
'DEP0001: `http.OutgoingMessage.prototype.flush`',
46+
'deprecations'
47+
),
48+
'DEP0001'
49+
);
50+
});
51+
52+
it('returns the DEP code regardless of the description text', () => {
53+
const getLegacySlug = createLegacySlugger();
54+
assert.strictEqual(
55+
getLegacySlug(
56+
'DEP0190: spawning .bat and .cmd files with child_process.spawn() with shell option',
57+
'deprecations'
58+
),
59+
'DEP0190'
60+
);
61+
});
62+
});
3963
});

src/generators/legacy-html/utils/slugger.mjs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,28 @@
11
'use strict';
22

3+
import { DEPRECATION_HEADING_REGEX } from '../constants.mjs';
4+
35
/**
46
* Creates a stateful slugger for legacy anchor links.
57
*
68
* Generates underscore-separated slugs in the form `{apiStem}_{text}`,
79
* appending `_{n}` for duplicates to preserve historical anchor compatibility.
810
*
11+
* Headings matching the `DEP####:` pattern return just the deprecation code
12+
* (e.g., `DEP0001`) as the anchor, matching the behavior of the old tooling
13+
* and preserving existing external links.
14+
*
915
* @returns {(text: string, apiStem: string) => string}
1016
*/
1117
export const createLegacySlugger =
1218
(counters = {}) =>
1319
(text, apiStem) => {
20+
const depMatch = DEPRECATION_HEADING_REGEX.exec(text);
21+
22+
if (depMatch) {
23+
return depMatch[1];
24+
}
25+
1426
const id = `${apiStem}_${text}`
1527
.toLowerCase()
1628
.replace(/^[^a-z0-9]+|[^a-z0-9]+$/g, '')

0 commit comments

Comments
 (0)