Git Product home page Git Product logo

mdvc's Introduction

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

mdvc's People

Contributors

youxam avatar

Stargazers

Tianze Ds avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.