You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A Vite plugin to simplify the importing of markdown files, with support for front-matter attributes. Uses front-matter under the hood for parsing markdown files.
This plugin does not transform the markdown content into JSX/React Elements, it simply returns a string of the markdown's body and an object with your front-matter attributes. You can use the markdown body string in a markdown renderer/formatter of your choice, like react-markdown.
importMarkdownPluginfrom'@goodforyou/vite-plugin-markdown-import';exportdefaultdefineConfig({// other config...plugins: [// other plugins...MarkdownPlugin(),],});
Files can then be imported in your vite application files, like so:
File:example.tsx
// you can use other markdown rendering libraries, this is an exampleimportMarkdownfrom'react-markdown';importTestMarkdownfrom'./test-markdown.md';exportdefaultfunctionTestComponent(){return(<div><Markdown>{TestMarkdown.body}</Markdown></div>);}
Typescript Config
If you are using typescript, at this point markdown files would be imported as type any. To fix that, add the following to your vite-env.d.ts file:
File:src/vite-env.d.ts
// other references.../// <reference types="@goodforyou/vite-plugin-markdown-import/client" />
At this point now, imported files will have the type MarkdownType which specifies an object of the following: