vite-plugin-frontmatter-markdown
A plugin enables you to import a Markdown file as various formats on your vite project.
Setup
npx i -D vite-plugin-frontmatter-markdown
Config
const fmPlugin = moduleexports = plugins:
Options
mode?: 'html' | 'toc' | 'react' | 'vue'markdown?:stringmarkdownIt?: MarkdownIt | MarkdownIt.Options
Enum for mode
is provided as Mode
console.logMode.HTML //=> 'html'console.logMode.TOC //=> 'toc'console.logMode.REACT //=> 'react'console.logMode.VUE //=> 'vue'
Mode examples:
Import Front Matter attributes
---title: Awesome Titledescription: Describe this awesome contenttags: - "great" - "awesome" - "rad"--- # This is awesome 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.
; console.logattributes //=> { title: 'Awesome Title', description: 'Describe this awesome content', tags: ['great', 'awesome', 'rad'] }
Mode.HTML
)
Import compiled HTML (# This is awesome 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.
; console.loghtml //=> "<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.TOC
)
Import ToC metadata (# vite 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. ## Status ## Getting Started # Notes
console.logtoc //=> [{ level: '1', content: 'vite' }, { level: '2', content: 'Status' }, { level: '2', content: 'Getting Started' }, { level: '1', content: 'Notes' },]
Mode.REACT
)
Import as a React component (import React from 'react'import ReactComponent from './contents/the-doc.md' { return <div> <ReactComponent /> </div>}
Custom Element on a markdown file can be runnable as a React component as well
# This is awesome Vite is <MyComponent type={'react'}>
import React from 'react'import ReactComponent from './contents/the-doc.md'import MyComponent from './my-component' { return <div> <ReactComponent = /> </div>}
MyComponent
on markdown perform as a React component.
Mode.VUE
)
Import as a Vue component (<template> <article> <markdown-content /> </article></template> <script>import { VueComponent } from './contents/the-doc.md' export default { components: { MarkdownContent: VueComponent }};</script>
Custom Element on a markdown file can be runnable as a Vue component as well
# This is awesome Vite is <MyComponent :type="'vue'">
<template> <article> <markdown-content /> </article></template> <script>import { VueComponent } from './contents/the-doc.md'import MyComponent from './my-component.vue' export default { components: { MarkdownContent: { extends: VueComponent, components: { MyComponent } } }};</script>
MyComponent
on markdown perform as a Vue component.
License
MIT