Installations
npm install vite-plugin-markdown
Developer Guide
Typescript
Yes
Module System
CommonJS
Node Version
18.19.0
NPM Version
10.3.0
Releases
Contributors
Unable to fetch Contributors
Languages
TypeScript (72.08%)
JavaScript (27.92%)
Love this project? Help keep it running — sponsor us today! 🚀
Developer
Download Statistics
Total Downloads
1,461,451
Last Day
5,278
Last Week
28,213
Last Month
110,554
Last Year
903,826
GitHub Statistics
267 Stars
281 Commits
45 Forks
3 Watching
8 Branches
9 Contributors
Bundle Size
359.65 kB
Minified
101.65 kB
Minified + Gzipped
Package Meta Information
Latest Version
2.2.0
Package Id
vite-plugin-markdown@2.2.0
Unpacked Size
23.14 kB
Size
7.12 kB
File Count
6
NPM Version
10.3.0
Node Version
18.19.0
Publised On
17 Jan 2024
Total Downloads
Cumulative downloads
Total Downloads
1,461,451
Last day
-37.4%
5,278
Compared to previous day
Last week
-19%
28,213
Compared to previous week
Last month
5.4%
110,554
Compared to previous month
Last year
160.1%
903,826
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Dependencies
4
Peer Dependencies
1
vite-plugin-markdown
A plugin enables you to import a Markdown file as various formats on your vite project.
Setup
npm i -D vite-plugin-markdown
For vite v1
npm i -D vite-plugin-markdown@vite-1
Config
1const mdPlugin = require('vite-plugin-markdown') 2 3module.exports = { 4 plugins: [mdPlugin(options)] 5}
Then you can import front matter attributes from .md
file as default.
1--- 2title: Awesome Title 3description: Describe this awesome content 4tags: 5 - "great" 6 - "awesome" 7 - "rad" 8--- 9 10# This is awesome 11 12Vite is an opinionated web dev build tool that serves your code via native ES Module imports during dev and bundles it with Rollup for production.
1import { attributes } from './contents/the-doc.md'; 2 3console.log(attributes) //=> { title: 'Awesome Title', description: 'Describe this awesome content', tags: ['great', 'awesome', 'rad'] }
Options
1mode?: ('html' | 'markdown' | 'toc' | 'react' | 'vue')[] 2markdown?: (body: string) => string 3markdownIt?: MarkdownIt | MarkdownIt.Options
Enum for mode
is provided as Mode
1import { Mode } from 'vite-plugin-markdown' 2 3console.log(Mode.HTML) //=> 'html' 4console.log(Mode.MARKDOWN) //=> 'markdown' 5console.log(Mode.TOC) //=> 'toc' 6console.log(Mode.REACT) //=> 'react' 7console.log(Mode.VUE) //=> 'vue'
"Mode" enables you to import markdown file in various formats (HTML, ToC, React/Vue Component)
Mode.HTML
Import compiled HTML
1# This is awesome 2 3Vite is an opinionated web dev build tool that serves your code via native ES Module imports during dev and bundles it with Rollup for production.
1import { html } from './contents/the-doc.md'; 2 3console.log(html) //=> "<h1>This is awesome</h1><p>ite is an opinionated web dev build tool that serves your code via native ES Module imports during dev and bundles it with Rollup for production.</p>"
Mode.MARKDOWN
Import the raw Markdown content
1import { markdown } from './contents/the-doc.md' 2 3console.log(markdown) //=> "# This is awesome \n Vite is an opinionated web dev build tool that serves your code via native ES Module imports during dev and bundles it with Rollup for production."
Mode.TOC
Import ToC metadata
1# vite 2 3Vite is an opinionated web dev build tool that serves your code via native ES Module imports during dev and bundles it with Rollup for production. 4 5## Status 6 7## Getting Started 8 9# Notes
1import { toc } from './contents/the-doc.md' 2 3console.log(toc) //=> [{ level: '1', content: 'vite' }, { level: '2', content: 'Status' }, { level: '2', content: 'Getting Started' }, { level: '1', content: 'Notes' },]
Mode.REACT
Import as a React component
1import React from 'react' 2import { ReactComponent } from './contents/the-doc.md' 3 4function MyReactApp() { 5 return ( 6 <div> 7 <ReactComponent /> 8 </div> 9}
Custom Element on a markdown file can be runnable as a React component as well
1# This is awesome 2 3Vite is <MyComponent type={'react'}>
1import React from 'react' 2import { ReactComponent } from './contents/the-doc.md' 3import { MyComponent } from './my-component' 4 5function MyReactApp() { 6 return ( 7 <div> 8 <ReactComponent MyComponent={MyComponent} /> 9 </div> 10}
MyComponent
on markdown perform as a React component.
Mode.VUE
Import as a Vue component
1<template> 2 <article> 3 <markdown-content /> 4 </article> 5</template> 6 7<script> 8import { VueComponent } from './contents/the-doc.md' 9 10export default { 11 components: { 12 MarkdownContent: VueComponent 13 } 14}; 15</script>
Custom Element on a markdown file can be runnable as a Vue component as well
1# This is awesome 2 3Vite is <MyComponent :type="'vue'">
1<template> 2 <article> 3 <markdown-content /> 4 </article> 5</template> 6 7<script> 8import { VueComponentWith } from './contents/the-doc.md' 9import MyComponent from './my-component.vue' 10 11export default { 12 components: { 13 MarkdownContent: VueComponentWith({ MyComponent }) 14 } 15}; 16</script>
MyComponent
on markdown perform as a Vue component.
Type declarations
In TypeScript project, need to declare typedefs for .md
file as you need.
1declare module '*.md' { 2 // "unknown" would be more detailed depends on how you structure frontmatter 3 const attributes: Record<string, unknown>; 4 5 // When "Mode.TOC" is requested 6 const toc: { level: string, content: string }[]; 7 8 // When "Mode.HTML" is requested 9 const html: string; 10 11 // When "Mode.RAW" is requested 12 const raw: string 13 14 // When "Mode.React" is requested. VFC could take a generic like React.VFC<{ MyComponent: TypeOfMyComponent }> 15 import React from 'react' 16 const ReactComponent: React.VFC; 17 18 // When "Mode.Vue" is requested 19 import { ComponentOptions, Component } from 'vue'; 20 const VueComponent: ComponentOptions; 21 const VueComponentWith: (components: Record<string, Component>) => ComponentOptions; 22 23 // Modify below per your usage 24 export { attributes, toc, html, ReactComponent, VueComponent, VueComponentWith }; 25}
Save as vite.d.ts
for instance.
License
MIT
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
3 existing vulnerabilities detected
Details
- Warn: Project is vulnerable to: GHSA-3xgq-45jj-v275
- Warn: Project is vulnerable to: GHSA-mwcw-c2x4-8c55
- Warn: Project is vulnerable to: GHSA-vg6x-rcgg-rjx6
Reason
Found 0/6 approved changesets -- score normalized to 0
Reason
0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/main.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:18: update your workflow using https://app.stepsecurity.io/secureworkflow/hmsk/vite-plugin-markdown/main.yml/main?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/main.yml:21: update your workflow using https://app.stepsecurity.io/secureworkflow/hmsk/vite-plugin-markdown/main.yml/main?enable=pin
- Warn: npmCommand not pinned by hash: .github/workflows/main.yml:27
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 npmCommand dependencies pinned
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'main'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 25 are checked with a SAST tool
Score
3.2
/10
Last Scanned on 2025-02-03
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More