Skip to content

Commit

Permalink
Improve deprecation message rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Ocupe committed Dec 2, 2024
1 parent 260d6b3 commit e0ab670
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions tooling/api-documenter/src/documenters/MarkdownDocumenter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,13 +225,38 @@ export class MarkdownDocumenter {
);

if (tsdocComment.deprecatedBlock) {
// Render the deprecation message as a "caution" callout add a "deprecated" prefix to the message.
let addedDeprecationString = false;
const newContent = tsdocComment.deprecatedBlock.content.nodes.reduce<DocNode[]>(
(acc, node) => {
if (!addedDeprecationString && node.kind === DocNodeKind.Paragraph) {
const paragraphChildren = node
.getChildNodes()
.reduce<DocNode[]>((paragraphNodes, paraNode) => {
if (!addedDeprecationString && paraNode.kind === DocNodeKind.PlainText) {
paragraphNodes.push(
new DocPlainText({
configuration,
text: 'This API is deprecated: ' + (paraNode as DocPlainText).text,
}),
);
addedDeprecationString = true;
} else {
paragraphNodes.push(paraNode);
}
return paragraphNodes;
}, []);
acc.push(new DocParagraph({ configuration }, paragraphChildren));
} else {
acc.push(node);
}
return acc;
},
[],
);

output.appendNode(
new Callout({ configuration, type: 'caution', variant: 'normal' }, [
new DocParagraph({ configuration }, [
new DocPlainText({ configuration, text: 'This API is deprecated:' }),
]),
...tsdocComment.deprecatedBlock.content.nodes,
]),
new Callout({ configuration, type: 'caution', variant: 'normal' }, [...newContent]),
);
}

Expand Down

0 comments on commit e0ab670

Please sign in to comment.