Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve doc gen #1038

Merged
merged 1 commit into from
Dec 3, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this omitting some elements? reduce vs map always makes me expect a non equivalent number of items being returned, same question above in L230

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is expected to return the same number of elements. I used reduce to iterate over the nodes and once we update the first Plain Text node we skip the first code branch and just push the elements onto the array.

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