remark plugin to support react-docgen-typescript in MDX
npm install remark-mdx-react-docgen-typescriptremark-mdx-react-docgen-typescriptš A mdx plugin to extract a react component documentation using react-docgen-typescript

``sh`
npm install -D remark-directive remark-mdx-react-docgen-typescript
`js`
import remarkReactDocgen from 'remark-mdx-react-docgen-typescript';
// or
// const remarkReactDocgen = require('remark-mdx-react-docgen-typescript').default;
See Using plugins for more instructions in the official documentation.
For example, given a file named example.mdx with the following contents:
`md`
::component-docs{file="./Component.tsx"}
The following script:
`js
import { readFile } from 'node:fs/promises';
import { compile } from '@mdx-js/mdx';
import remarkDirective from 'remark-directive';
import remarkReactDocgen from 'remark-mdx-react-docgen-typescript';
const { contents } = await compile(await readFile('example.mdx'), {
jsx: true,
remarkPlugins: [remarkDirective, remarkReactDocgen],
});
console.log(contents);
`
Roughly yields:
`jsx`
export default function MDXContent() {
return
"tags": {},
"filePath": "${cwd}/__fixtures__/Component.tsx",
"description": "",
"displayName": "Component",
"methods": [],
"props": {...}
...
}]}
/>
}
You may use @mdx-js/react to define the component for ComponentDocs tag name:
`jsx@mdx-js/esbuild
import { MDXProvider } from '@mdx-js/react';
import ComponentDocs from './ComponentDocs';
// ^-- Assumes an integration is used to compile MDX to JS, such as
// , @mdx-js/loader, @mdx-js/node-loader, or@mdx-js/rollup
// , and that it is configured withoptions.providerImportSource: '@mdx-js/react'
// .
/* @type {import('mdx/types.js').MDXComponents} /
const components = {
ComponentDocs,
};
console.log(
);
`
The file path is relative to the markdown file path. You can use at the start of the path to import files relatively from the rootDir:
`md`
::component-docs{file="
You may also specify additional attributes that will be forwarded as props to ComponentDocs component:
`md`
::component-docs{file="./Component.tsx" extraProp="value"}
- componentName: string: The name of tag/component this plugin will use in JSX. Defaults to ComponentDocs.directiveName: string
- : The directive name. Defaults to component-docs.fileAttributeName: string
- : The attribute name for file path. Defaults to file.rootDir: string
- : Change what refers to. Defaults to process.cwd().reactDocGenOptions: object
- : Options for react-docgen-typescript.
After installing dependencies with npm install, the tests can be run with: npm test`
Rippling People Center Inc.
Apache 2.0