vue-md-loader
Webpack loader for converting Markdown files to ✨ALIVE Vue components.
Webpack loader for converting Markdown files to ALIVE Vue components.
- Configurable Markdown-It parser.
- Built-in syntax highlighter with highlightjs.
- Live demo support. Extremely useful for document examples.
- Hot reload.
Example
This page vue-md-loader.wxsm.space is generated by a markdown file.
source: /example
Install
NPM:
Yarn:
Usage
Basic
Simply use vue-md-loader
to load .md
files and chain it with your vue-loader
.
Note that to get code highlighting to work, you need to:
- include one of the highlight.js css files into your project, for example:
highlight.js/styles/github-gist.css
. - specify a lang in code block. ref: creating and highlighting code blocks.
With Options
Markdown Alive!
A live demo is:
becomes something like:
A Vue component with all it's <template>
, <script>
and <style>
settled will be inserted before it's source code block.
Multiple lives inside a single markdown file is supported by:
- All
<script>
from different code blocks:- code inside
export default
will be extract into it's own Vue component with no conflicts. - code before
export default
will be extract into the same top-level component.
- code inside
- All
<style>
from different code blocks will be extract into the same top-level component.
Note:
- Loader will treat the entire block as template if no
<template>
found in live block. - You will need runtime + compiler build of Vue.js for this feature. For example:
Options
wrapper
String. Default: section
The wrapper of entire markdown content, can be HTML tag name or Vue component name.
markdown
Object.
Markdown-It options. Default:
plugins
Array.
Markdown-It plugins list. For example:
rules
Object.
Markdown-It renderer rules. For example:
preProcess
Function. For example:
process
Function. For example
afterProcess
Function. For example:
live
Boolean. Default: true
Enable / Disable live detecting and assembling.
livePattern
Regex. Default: /<!--[\s]*?([-\w]+?).vue[\s]*?-->/i
A code block with livePattern
inside itself becomes a live block. The matched body will become the live Vue component's name and reference (note that they must be unique to each other within the same page).
afterProcessLiveTemplate
Function. Default: null
Use this if you wish to change the live template manually after process (e.g. add wrappers). For example: