docusaurus-plugin-typedoc-api
Version:
Docusaurus plugin that provides source code API documentation powered by TypeDoc.
66 lines (62 loc) • 2.08 kB
JavaScript
;
const react = require('react');
const Markdown = require('./Markdown.js');
const jsxRuntime = require('react/jsx-runtime');
// https://github.com/TypeStrong/typedoc-default-themes/blob/master/src/default/partials/comment.hbs
function hasComment(comment) {
if (!comment) {
return false;
}
return Boolean(comment.summary?.some(x => x.kind !== 'text' || x.text !== '') || comment.blockTags && comment.blockTags?.length > 0);
}
function displayPartsToMarkdown(parts) {
return parts.map(part => {
if (part.kind === 'inline-tag') {
return `{${part.tag} ${part.text}}`;
}
return part.text;
}).join('');
}
function Comment({
comment,
root,
hideTags = []
}) {
if (!comment || !hasComment(comment)) {
return null;
}
// Hide custom tags.
hideTags.push('@reference');
const blockTags = comment.blockTags?.filter(tag => {
if (hideTags.includes(tag.tag)) {
return false;
}
return tag.tag !== '@default';
}) ?? [];
return /*#__PURE__*/jsxRuntime.jsxs("div", {
className: `tsd-comment tsd-typography ${root ? 'tsd-comment-root' : ''}`,
children: [!!comment.summary && /*#__PURE__*/jsxRuntime.jsx("div", {
className: "lead",
children: /*#__PURE__*/jsxRuntime.jsx(Markdown.Markdown, {
content: displayPartsToMarkdown(comment.summary)
})
}), blockTags.length > 0 && /*#__PURE__*/jsxRuntime.jsx("dl", {
className: "tsd-comment-tags",
children: blockTags.map(tag => /*#__PURE__*/jsxRuntime.jsxs(react.Fragment, {
children: [/*#__PURE__*/jsxRuntime.jsx("dt", {
children: /*#__PURE__*/jsxRuntime.jsx("strong", {
children: tag.tag
})
}), /*#__PURE__*/jsxRuntime.jsx("dd", {
children: /*#__PURE__*/jsxRuntime.jsx(Markdown.Markdown, {
content: displayPartsToMarkdown(tag.content)
})
})]
}, tag.tag))
})]
});
}
exports.Comment = Comment;
exports.displayPartsToMarkdown = displayPartsToMarkdown;
exports.hasComment = hasComment;
//# sourceMappingURL=Comment.js.map