Skip to content

Commit 9e055f0

Browse files
authored
Improve doc gen around deprecated notes (#1038)
1 parent 5c398b8 commit 9e055f0

File tree

1 file changed

+31
-6
lines changed

1 file changed

+31
-6
lines changed

tooling/api-documenter/src/documenters/MarkdownDocumenter.ts

+31-6
Original file line numberDiff line numberDiff line change
@@ -225,13 +225,38 @@ export class MarkdownDocumenter {
225225
);
226226

227227
if (tsdocComment.deprecatedBlock) {
228+
// Render the deprecation message as a "caution" callout add a "deprecated" prefix to the message.
229+
let addedDeprecationString = false;
230+
const newContent = tsdocComment.deprecatedBlock.content.nodes.reduce<DocNode[]>(
231+
(acc, node) => {
232+
if (!addedDeprecationString && node.kind === DocNodeKind.Paragraph) {
233+
const paragraphChildren = node
234+
.getChildNodes()
235+
.reduce<DocNode[]>((paragraphNodes, paraNode) => {
236+
if (!addedDeprecationString && paraNode.kind === DocNodeKind.PlainText) {
237+
paragraphNodes.push(
238+
new DocPlainText({
239+
configuration,
240+
text: 'This API is deprecated: ' + (paraNode as DocPlainText).text,
241+
}),
242+
);
243+
addedDeprecationString = true;
244+
} else {
245+
paragraphNodes.push(paraNode);
246+
}
247+
return paragraphNodes;
248+
}, []);
249+
acc.push(new DocParagraph({ configuration }, paragraphChildren));
250+
} else {
251+
acc.push(node);
252+
}
253+
return acc;
254+
},
255+
[],
256+
);
257+
228258
output.appendNode(
229-
new Callout({ configuration, type: 'caution', variant: 'normal' }, [
230-
new DocParagraph({ configuration }, [
231-
new DocPlainText({ configuration, text: 'This API is deprecated:' }),
232-
]),
233-
...tsdocComment.deprecatedBlock.content.nodes,
234-
]),
259+
new Callout({ configuration, type: 'caution', variant: 'normal' }, [...newContent]),
235260
);
236261
}
237262

0 commit comments

Comments
 (0)