diff --git a/.changeset/tidy-deprecations-smile.md b/.changeset/tidy-deprecations-smile.md new file mode 100644 index 00000000..d9e7c7bb --- /dev/null +++ b/.changeset/tidy-deprecations-smile.md @@ -0,0 +1,5 @@ +--- +'@node-core/doc-kit': patch +--- + +Preserve deprecation codes in generated table-of-contents labels. diff --git a/src/generators/jsx-ast/utils/__tests__/buildBarProps.test.mjs b/src/generators/jsx-ast/utils/__tests__/buildBarProps.test.mjs index 38ea8d55..bd5fe6d8 100644 --- a/src/generators/jsx-ast/utils/__tests__/buildBarProps.test.mjs +++ b/src/generators/jsx-ast/utils/__tests__/buildBarProps.test.mjs @@ -116,6 +116,28 @@ describe('extractHeadings', () => { assert.equal(result[1].value, 'new Buffer'); }); + it('preserves deprecation codes in heading labels', () => { + const entries = [ + { + heading: { + depth: 2, + data: { + text: 'DEP0001: `http.OutgoingMessage.prototype.flush`', + name: 'http.OutgoingMessage.prototype.flush', + slug: 'DEP0001', + }, + }, + }, + ]; + + const result = extractHeadings(entries); + + assert.equal( + result[0].value, + 'DEP0001: http.OutgoingMessage.prototype.flush' + ); + }); + it('drops overload headings and links to the first signature', () => { const entries = [ { diff --git a/src/generators/jsx-ast/utils/buildBarProps.mjs b/src/generators/jsx-ast/utils/buildBarProps.mjs index cdad9536..d535c30a 100644 --- a/src/generators/jsx-ast/utils/buildBarProps.mjs +++ b/src/generators/jsx-ast/utils/buildBarProps.mjs @@ -60,8 +60,9 @@ const headingLabel = data => { data.text // Remove any containing code blocks .replace(/`/g, '') - // Remove any prefixes (i.e. 'Class:') - .replace(/^[^:]+:/, '') + // Remove any prefixes (i.e. 'Class:'), except deprecation codes + // (i.e. 'DEP0001:') which are part of the label + .replace(/^(?!DEP\d+:)[^:]+:/, '') // Trim the remaining whitespace .trim() );