storybook-addon-jsdoc-to-mdx
Version:
Storybook addon that automatically generates MDX documentation from JSDoc comments in your TypeScript and JavaScript files. Supports HTML tags in comments, complex TypeScript types, and integrates seamlessly with Storybook 7.x and 8.x.
33 lines (32 loc) • 1.62 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMdxContent = createMdxContent;
const utils_1 = require("./utils");
function createMdxContent(jsDocComments, pathName) {
let mdxContent = `import { Meta } from '@storybook/blocks';\n\n<Meta title="${pathName}" />\n\n`;
jsDocComments.forEach((comment) => {
if (comment.name != "Unnamed") {
mdxContent += `# ${comment.name}\n\n`;
mdxContent += `\`${pathName}\`\n`;
mdxContent += `**AST Node Type:** *${comment.type}*\n\n`;
mdxContent += (0, utils_1.formatJsDocComment)(comment.comment) + "\n\n";
mdxContent += `#### Source Code:\n\n`;
const codeSnippet = comment.type === "MethodDeclaration"
? (0, utils_1.extractMethodFromCode)(comment.code, comment.name)
: (0, utils_1.removeCommentsFromCode)(comment.code);
mdxContent += "```ts\n" + codeSnippet + "\n```\n\n";
}
else {
mdxContent += `----- \n`;
mdxContent += `\`${pathName}\`\n`;
mdxContent += `**AST Node Type:** *${comment.type}*\n`;
mdxContent += (0, utils_1.formatJsDocComment)(comment.comment) + "\n\n";
mdxContent += `#### Source Code:\n\n`;
const codeSnippet = comment.type === "MethodDeclaration"
? (0, utils_1.extractMethodFromCode)(comment.code, comment.name)
: (0, utils_1.removeCommentsFromCode)(comment.code);
mdxContent += "```ts\n" + codeSnippet + "\n```\n\n";
}
});
return mdxContent;
}
;