File tree Expand file tree Collapse file tree 3 files changed +41
-0
lines changed
src/generators/legacy-html Expand file tree Collapse file tree 3 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 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 = / ^ ( D E P \d + ) : / ;
Original file line number Diff line number Diff 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} ) ;
Original file line number Diff line number Diff line change 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 */
1117export 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 - z 0 - 9 ] + | [ ^ a - z 0 - 9 ] + $ / g, '' )
You can’t perform that action at this time.
0 commit comments