@md-plugins/vite-md-plugin
@md-plugins/vite-md-plugin
See the documentation for more details.
An opinionated Vite plugin that transforms Markdown files into Vue Single File Components. It is the Markdown route engine used by Q-Press, and it can also be used directly in Vue/Vite and Quasar apps that own their own layout, navigation, search, and SSG flow.
Features
- Markdown to Vue SFC Transformation: Converts Markdown files into Vue Single File Components.
- Q-Press-compatible Markdown features: Supports imports, code blocks, containers, tables, links, frontmatter, titles, and more.
- Navigation Menu Integration: Accepts a menu structure for sidebar and route-aware Markdown output.
- Configurable Markdown Root: Points the plugin at the Markdown folder your project owns.
- Direct-use friendly: Useful without Q-Press when an app wants custom layouts around Markdown pages.
md-plugins Used
The viteMdPlugin is built on top of the following plugins:
| Plugin | Description | Readme |
|---|---|---|
@md-plugins/md-plugin-imports |
Extracts and processes <script import> blocks from Markdown. |
README |
@md-plugins/md-plugin-codeblocks |
Enhances code block rendering with syntax highlighting, tabs, and more. | README |
@md-plugins/md-plugin-blockquote |
Adds customizable CSS classes to blockquotes. | README |
@md-plugins/md-plugin-headers |
Extracts and processes headers for generating ToCs or managing headers. | README |
@md-plugins/md-plugin-inlinecode |
Adds a custom class to inline code blocks for styling. | README |
@md-plugins/md-plugin-link |
Converts Markdown links into Vue components for SPA-friendly routing. | README |
@md-plugins/md-plugin-table |
Adds custom classes and attributes to Markdown tables. | README |
@md-plugins/md-plugin-title |
Extracts the first header in Markdown as the page title. | README |
@md-plugins/md-plugin-frontmatter |
Extracts and processes frontmatter content from Markdown files. | README |
@md-plugins/md-plugin-containers |
Adds custom containers for callouts, warnings, and more. | README |
@md-plugins/shared |
Shared utilities and types for the plugins. | README |
Installation
Install the plugin via your preferred package manager:
# with pnpm:
pnpm add @md-plugins/vite-md-plugin
# with bun:
bun add @md-plugins/vite-md-plugin
# with Yarn:
yarn add @md-plugins/vite-md-plugin
# with npm:
npm install @md-plugins/vite-md-plugin
Usage
Basic Setup with Vite
To use the viteMdPlugin, configure it in your Vite project:
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import { viteMdPlugin } from '@md-plugins/vite-md-plugin'
const menu = [] // Define your navigation menu structure here
const basePath = '/docs' // Base path prefix
export default defineConfig({
plugins: [vue(), viteMdPlugin({ path: basePath, menu })],
})
Quasar Framework Configuration
If you’re using the Quasar Framework, additional configuration is needed to enable support for .md files:
- Update
quasar.config.(js|ts):
-
import { viteMdPlugin, type MenuItem, type MarkdownOptions } from '@md-plugins/vite-md-plugin' import { menu } from './src/assets/menu' // be sure to create this file export default defineConfig((ctx) => { // ... build: { vueRouterMode: 'history', // Required for proper hash link handling viteVuePluginOptions: { include: [/\.(vue|md)$/], // Include Markdown files }, vitePlugins: [ viteMdPlugin({ path: ctx.appPaths.srcDir + '/markdown', menu: menu as MenuItem[], // config: myOptions as MarkdownOptions, }), // ... ], }, framework: { autoImportVueExtensions: ['vue', 'md'], // Enable auto-import for Markdown extensions },
- Ensure that your routes and hash links are compatible with Vue Router's history mode.
Navigation Menu Integration
The viteMdPlugin allows you to define a navigation structure that can be updated dynamically based on the Markdown files in your project:
const menu = [
{ name: 'Home', path: '/home' },
{ name: 'About', path: '/about' },
]
This menu is passed as a parameter to the plugin and can be used to build a dynamic sidebar or navigation bar in your application.
Options
The viteMdPlugin accepts the following parameters:
| Parameter | Type | Description |
|---|---|---|
| path | string | The base path prefix for routing or file resolution. |
| menu | MenuItem[] | An array representing the navigation menu structure. Each item should have name and path. |
MenuItem Type
The menu parameter should conform to the following structure:
export interface MenuItem {
name: string
path?: string
icon?: string
iconColor?: string
rightIcon?: string
rightIconColor?: string
badge?: string
children?: MenuItem[]
external?: boolean
expanded?: boolean
}
Testing
To run the tests for this plugin, use the following command:
pnpm test
Documentation
In case this README falls out of date, please refer to the documentation for the latest information.
Support
If vite-md-plugin is useful in your workflow and you want to support ongoing maintenance:
- GitHub Sponsors: https://github.com/sponsors/hawkeye64
- PayPal: https://paypal.me/hawkeye64
License
This project is licensed under the MIT License. See the LICENSE file for details.
Related Packages
A Vite plugin for @md-plugins for handling imported examples in markdown files.
A Vite plugin for @md-plugins static route inventory and future SSG output.
Version History
| Version | Released | License |
|---|---|---|
| 2.2.0 | MIT | |
| 2.1.0 | MIT | |
| 2.0.4 | MIT | |
| 2.0.3 | MIT | |
| 2.0.2 | MIT | |
| 2.0.1 | MIT | |
| 2.0.0 | MIT | |
| 1.2.0 | MIT | |
| 1.1.0 | MIT | |
| 1.0.0 | MIT |
Pre-releases (77)
| Version | Released | License |
|---|---|---|
| 0.1.0-rc.19 | MIT | |
| 0.1.0-rc.18 | MIT | |
| 0.1.0-rc.17 | MIT | |
| 0.1.0-rc.16 | MIT | |
| 0.1.0-rc.15 | MIT | |
| 0.1.0-rc.14 | MIT | |
| 0.1.0-rc.13 | MIT | |
| 0.1.0-rc.12 | MIT | |
| 0.1.0-rc.11 | MIT | |
| 0.1.0-rc.10 | MIT | |
| 0.1.0-rc.9 | MIT | |
| 0.1.0-rc.8 | MIT | |
| 0.1.0-rc.7 | MIT | |
| 0.1.0-rc.6 | MIT | |
| 0.1.0-rc.5 | MIT | |
| 0.1.0-rc.4 | MIT | |
| 0.1.0-rc.3 | MIT | |
| 0.1.0-rc.2 | MIT | |
| 0.1.0-rc.1 | MIT | |
| 0.1.0-rc.0 | MIT | |
| 0.1.0-beta.29 | MIT | |
| 0.1.0-beta.28 | MIT | |
| 0.1.0-beta.27 | MIT | |
| 0.1.0-beta.26 | MIT | |
| 0.1.0-beta.25 | MIT | |
| 0.1.0-beta.24 | MIT | |
| 0.1.0-beta.23 | MIT | |
| 0.1.0-beta.22 | MIT | |
| 0.1.0-beta.21 | MIT | |
| 0.1.0-beta.20 | MIT |
Showing the latest 30 of 77. See every release on npm