0.0.16 • Published 11 months ago

mdvc v0.0.16

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

mdvc

mdvc (markdown-vue-component) is a library to compile markdown/vue/js/ts/css files to vue components directly in your browser.

Live Demo

Installation

npm install mdvc
# or
yarn add mdvc

Usage

import { createApp, defineAsyncComponent } from 'vue'
import mdvc from 'mdvc';

const files = {
    'main.md': `

## Hello World!

\`\`\`js
console.log(123)
\`\`\`

<h1>{{ msg }}</h1>
<button @click="msg = msg.split('').reverse().join('')">
    Reverse
</button>

<script setup>
import './main.css'
import { ref } from 'vue'
const msg = ref("Hello World!")
</script>

<style scoped>
h1 {
    color: red;
}
</style>`,

    'main.css': `

@import url('./files/part.css') screen and (min-width: 500px);
h1 {
    text-decoration: underline;
}`,
    'files/part.css': `

h1 {
    text-align: center;
}`

}

createApp(defineAsyncComponent(() => mdvc('main.md', { files }))).mount('#app')

Important: a known issue

See vue-sfc-component.

Definiton

import { Component } from 'vue'
import { File } from 'vue-sfc-component';

type MaybePromise<T> = T | Promise<T>
type FileContent = string | ArrayBuffer | Blob | Response

export default async function(
    mainfile: string,
    options?: {
        imports?: Record<string, any>;
        files?: Record<string, FileContent | URL>;
        getFile?: (path: string) => MaybePromise<FileContent | URL>;
        renderStyles?: (css: string) => MaybePromise<string>;
        catch?: (errors: Array<string | Error>) => MaybePromise<void>;
        fileConvertRule?: (file: File) => MaybePromise<void>;
        markdown?: Markdown.Options;
        extend?: (md: Markdown) => void;
    }
) : Promise<Component>

Options

1. markdown

markdown-it options

2. extend

You can extend markdown-it by passing a function to extend option.

import mdvc from 'mdvc';
import katex from 'markdown-it-katex'

mdvc('main.md', {
    extend(md) {
        md.use(katex)
    },
    // ...
})

Other options are the same as vue-sfc-component options.

License

MIT

0.0.10

11 months ago

0.0.11

11 months ago

0.0.12

11 months ago

0.0.13

11 months ago

0.0.14

11 months ago

0.0.15

11 months ago

0.0.9

11 months ago

0.0.16

11 months ago

0.0.8

11 months ago

0.0.7

2 years ago

0.0.5

2 years ago

0.0.6

2 years ago

0.0.4

2 years ago

0.0.3

2 years ago

0.0.2

2 years ago

0.0.1

2 years ago