Skip to content

Commit 23b2c23

Browse files
committed
initial commit
Signed-off-by: YouXam <[email protected]>
0 parents  commit 23b2c23

12 files changed

+1359
-0
lines changed

.gitignore

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
dist/
2+
node_modules/
3+
public/
4+
.DS_Store

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2024 YouXam
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+114
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
# mdvc
2+
3+
mdvc (markdown-vue-component) is a library to compile markdown/vue/js/ts/css files to vue components directly in your browser.
4+
5+
## Installation
6+
7+
```bash
8+
npm install mdvc
9+
# or
10+
yarn add mdvc
11+
```
12+
13+
## Usage
14+
15+
```js
16+
17+
import { createApp, defineAsyncComponent } from 'vue'
18+
import mdvc from 'mdvc';
19+
20+
const files = {
21+
'main.md': `
22+
23+
## Hello World!
24+
25+
\`\`\`js
26+
console.log(123)
27+
\`\`\`
28+
29+
<h1>{{ msg }}</h1>
30+
<button @click="msg = msg.split('').reverse().join('')">
31+
Reverse
32+
</button>
33+
34+
<script setup>
35+
import './main.css'
36+
import { ref } from 'vue'
37+
const msg = ref("Hello World!")
38+
</script>
39+
40+
<style scoped>
41+
h1 {
42+
color: red;
43+
}
44+
</style>`,
45+
46+
'main.css': `
47+
48+
@import url('./files/part.css') screen and (min-width: 500px);
49+
h1 {
50+
text-decoration: underline;
51+
}`,
52+
'files/part.css': `
53+
54+
h1 {
55+
text-align: center;
56+
}`
57+
58+
}
59+
60+
createApp(defineAsyncComponent(() => mdvc('main.md', { files }))).mount('#app')
61+
62+
```
63+
64+
## Definiton
65+
66+
```ts
67+
import { Component } from 'vue'
68+
import { File } from 'vue-sfc-component';
69+
70+
type MaybePromise<T> = T | Promise<T>
71+
type FileContent = string | ArrayBuffer | Blob | Response
72+
73+
export default async function(
74+
mainfile: string,
75+
options?: {
76+
imports?: Record<string, any>;
77+
files?: Record<string, FileContent | URL>;
78+
getFile?: (path: string) => MaybePromise<FileContent | URL>;
79+
renderStyles?: (css: string) => MaybePromise<string>;
80+
catch?: (errors: Array<string | Error>) => MaybePromise<void>;
81+
fileConvertRule?: (file: File) => MaybePromise<void>;
82+
markdown?: Markdown.Options;
83+
extend?: (md: Markdown) => void;
84+
}
85+
) : Promise<Component>
86+
```
87+
88+
## Options
89+
90+
### 1. `markdown`
91+
92+
`markdown-it` options
93+
94+
### 2. `extend`
95+
96+
You can extend `markdown-it` by passing a function to `extend` option.
97+
98+
```js
99+
import mdvc from 'mdvc';
100+
import katex from 'markdown-it-katex'
101+
102+
mdvc('main.md', {
103+
extend(md) {
104+
md.use(katex)
105+
},
106+
// ...
107+
})
108+
```
109+
110+
Other options are the same as [vue-sfc-component](https://github.com/YouXam/vue-sfc-component) options.
111+
112+
## License
113+
114+
[MIT](LICENSE)

package.json

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"name": "mdvc",
3+
"version": "0.0.1",
4+
"description": "Convert markdown-vue files to vue components.",
5+
"main": "dist/src/index.js",
6+
"scripts": {
7+
"dev": "vite dev --open test/index.html",
8+
"build": "tsc"
9+
},
10+
"author": "YouXam",
11+
"license": "MIT",
12+
"type": "module",
13+
"files": [
14+
"dist/"
15+
],
16+
"repository": {
17+
"type": "git",
18+
"url": "https://github.com/YouXam/mdvc.git"
19+
},
20+
"devDependencies": {
21+
"@types/markdown-it": "^13.0.7",
22+
"@vitejs/plugin-vue": "^5.0.3",
23+
"typescript": "^5.3.3",
24+
"vite": "^5.0.12",
25+
"vue": "^3.4.15"
26+
},
27+
"dependencies": {
28+
"markdown-it": "^14.0.0",
29+
"vue-sfc-component": "^0.0.7"
30+
}
31+
}

0 commit comments

Comments
 (0)