@md-plugins/vite-md-plugin 0.1.0-alpha.25 → 0.1.0-alpha.27
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +31 -35
- package/dist/index.d.mts +26 -1
- package/dist/index.d.ts +26 -1
- package/dist/index.mjs +130 -89
- package/package.json +13 -13
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @md-plugins/viteMdPlugin
|
|
2
2
|
|
|
3
|
+
See the [documentation](https://md-plugins.netlify.app/vite-plugins/vite-md-plugin/overview) for more details.
|
|
4
|
+
|
|
3
5
|
An **opinionated Vite plugin** that transforms Markdown files into Vue Single File Components (SFCs). This plugin integrates Markdown processing directly into your Vite-based Vue project, enabling seamless Markdown-to-Vue workflows.
|
|
4
6
|
|
|
5
7
|
## Features
|
|
@@ -32,12 +34,12 @@ The `viteMdPlugin` is built on top of the following plugins:
|
|
|
32
34
|
Install the plugin via your preferred package manager:
|
|
33
35
|
|
|
34
36
|
```bash
|
|
35
|
-
#
|
|
36
|
-
npm install @md-plugins/vite-md-plugin
|
|
37
|
-
# Or with Yarn:
|
|
38
|
-
yarn add @md-plugins/vite-md-plugin
|
|
39
|
-
# Or with pnpm:
|
|
37
|
+
# with pnpm:
|
|
40
38
|
pnpm add @md-plugins/vite-md-plugin
|
|
39
|
+
# with Yarn:
|
|
40
|
+
yarn add @md-plugins/vite-md-plugin
|
|
41
|
+
# with npm:
|
|
42
|
+
npm install @md-plugins/vite-md-plugin
|
|
41
43
|
```
|
|
42
44
|
|
|
43
45
|
## Usage
|
|
@@ -65,38 +67,32 @@ If you’re using the Quasar Framework, additional configuration is needed to en
|
|
|
65
67
|
|
|
66
68
|
1. Update `quasar.config.(js|ts)`:
|
|
67
69
|
|
|
68
|
-
```js
|
|
69
|
-
import { viteMdPlugin } from '@md-plugins/vite-md-plugin'
|
|
70
|
-
import { menu } from './src/.q-press/assets/menu'
|
|
71
|
-
|
|
72
|
-
export default defineConfig((ctx) => {
|
|
73
|
-
// ...
|
|
74
|
-
```
|
|
70
|
+
- ```js
|
|
71
|
+
import { viteMdPlugin } from '@md-plugins/vite-md-plugin'
|
|
72
|
+
import { menu } from './src/.q-press/assets/menu' // be sure to create this file
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
},
|
|
83
|
-
|
|
84
|
-
vitePlugins: [
|
|
85
|
-
[
|
|
86
|
-
viteMdPlugin,
|
|
87
|
-
{
|
|
88
|
-
path: ctx.appPaths.srcDir + '/markdown',
|
|
89
|
-
menu: sidebar as MenuItem[],
|
|
74
|
+
export default defineConfig((ctx) => {
|
|
75
|
+
// ...
|
|
76
|
+
build: {
|
|
77
|
+
vueRouterMode: 'history', // Required for proper hash link handling
|
|
78
|
+
viteVuePluginOptions: {
|
|
79
|
+
include: [/\.(vue|md)$/], // Include Markdown files
|
|
90
80
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
81
|
+
vitePlugins: [
|
|
82
|
+
[
|
|
83
|
+
viteMdPlugin,
|
|
84
|
+
{
|
|
85
|
+
path: ctx.appPaths.srcDir + '/markdown',
|
|
86
|
+
menu: sidebar as MenuItem[],
|
|
87
|
+
},
|
|
88
|
+
],
|
|
89
|
+
// ...
|
|
90
|
+
],
|
|
91
|
+
},
|
|
92
|
+
framework: {
|
|
93
|
+
autoImportVueExtensions: ['vue', 'md'], // Enable auto-import for Markdown extensions
|
|
94
|
+
},
|
|
95
|
+
```
|
|
100
96
|
|
|
101
97
|
2. Ensure that your routes and hash links are compatible with Vue Router's history mode.
|
|
102
98
|
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
+
import { Options } from 'markdown-it';
|
|
3
|
+
import { BlockquotePluginOptions } from '@md-plugins/md-plugin-blockquote';
|
|
4
|
+
import { CodeblockPluginOptions } from '@md-plugins/md-plugin-codeblocks';
|
|
5
|
+
import { FrontmatterPluginOptions } from '@md-plugins/md-plugin-frontmatter';
|
|
6
|
+
import { HeadersPluginOptions } from '@md-plugins/md-plugin-headers';
|
|
7
|
+
import { ImagePluginOptions } from '@md-plugins/md-plugin-image';
|
|
8
|
+
import { InlineCodePluginOptions } from '@md-plugins/md-plugin-inlinecode';
|
|
9
|
+
import { LinkPluginOptions } from '@md-plugins/md-plugin-link';
|
|
10
|
+
import { TablePluginOptions } from '@md-plugins/md-plugin-table';
|
|
2
11
|
|
|
12
|
+
interface MarkdownOptions extends Options {
|
|
13
|
+
html?: boolean;
|
|
14
|
+
linkify?: boolean;
|
|
15
|
+
typographer?: boolean;
|
|
16
|
+
breaks?: boolean;
|
|
17
|
+
blockquote?: BlockquotePluginOptions;
|
|
18
|
+
codeblocks?: CodeblockPluginOptions;
|
|
19
|
+
frontmatter?: FrontmatterPluginOptions;
|
|
20
|
+
headers?: HeadersPluginOptions | boolean;
|
|
21
|
+
image?: ImagePluginOptions;
|
|
22
|
+
inlinecode?: InlineCodePluginOptions;
|
|
23
|
+
link?: LinkPluginOptions;
|
|
24
|
+
table?: TablePluginOptions;
|
|
25
|
+
}
|
|
3
26
|
interface MenuItem {
|
|
4
27
|
name: string;
|
|
5
28
|
path?: string;
|
|
@@ -37,6 +60,7 @@ interface RelatedItem {
|
|
|
37
60
|
interface UserConfig {
|
|
38
61
|
path: string;
|
|
39
62
|
menu: MenuItem[];
|
|
63
|
+
config?: MarkdownOptions;
|
|
40
64
|
}
|
|
41
65
|
|
|
42
66
|
/**
|
|
@@ -46,8 +70,9 @@ interface UserConfig {
|
|
|
46
70
|
* @param userConfig - The configuration object for the Vite Markdown plugin.
|
|
47
71
|
* @param userConfig.path - The base path prefix to be used for routing or file resolution.
|
|
48
72
|
* @param userConfig.menu - An array of MenuItem objects representing the navigation menu structure.
|
|
73
|
+
* @param userConfig.config - Additional configuration options for the Markdown processing.
|
|
49
74
|
* @returns A Vite Plugin object pre-configured with the provided settings for Markdown processing.
|
|
50
75
|
*/
|
|
51
76
|
declare function viteMdPlugin(userConfig: UserConfig): Plugin;
|
|
52
77
|
|
|
53
|
-
export { type FlatMenu, type FlatMenuEntry, type MenuItem, type MenuNode, type NavItem, type RelatedItem, type UserConfig, viteMdPlugin };
|
|
78
|
+
export { type FlatMenu, type FlatMenuEntry, type MarkdownOptions, type MenuItem, type MenuNode, type NavItem, type RelatedItem, type UserConfig, viteMdPlugin };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
+
import { Options } from 'markdown-it';
|
|
3
|
+
import { BlockquotePluginOptions } from '@md-plugins/md-plugin-blockquote';
|
|
4
|
+
import { CodeblockPluginOptions } from '@md-plugins/md-plugin-codeblocks';
|
|
5
|
+
import { FrontmatterPluginOptions } from '@md-plugins/md-plugin-frontmatter';
|
|
6
|
+
import { HeadersPluginOptions } from '@md-plugins/md-plugin-headers';
|
|
7
|
+
import { ImagePluginOptions } from '@md-plugins/md-plugin-image';
|
|
8
|
+
import { InlineCodePluginOptions } from '@md-plugins/md-plugin-inlinecode';
|
|
9
|
+
import { LinkPluginOptions } from '@md-plugins/md-plugin-link';
|
|
10
|
+
import { TablePluginOptions } from '@md-plugins/md-plugin-table';
|
|
2
11
|
|
|
12
|
+
interface MarkdownOptions extends Options {
|
|
13
|
+
html?: boolean;
|
|
14
|
+
linkify?: boolean;
|
|
15
|
+
typographer?: boolean;
|
|
16
|
+
breaks?: boolean;
|
|
17
|
+
blockquote?: BlockquotePluginOptions;
|
|
18
|
+
codeblocks?: CodeblockPluginOptions;
|
|
19
|
+
frontmatter?: FrontmatterPluginOptions;
|
|
20
|
+
headers?: HeadersPluginOptions | boolean;
|
|
21
|
+
image?: ImagePluginOptions;
|
|
22
|
+
inlinecode?: InlineCodePluginOptions;
|
|
23
|
+
link?: LinkPluginOptions;
|
|
24
|
+
table?: TablePluginOptions;
|
|
25
|
+
}
|
|
3
26
|
interface MenuItem {
|
|
4
27
|
name: string;
|
|
5
28
|
path?: string;
|
|
@@ -37,6 +60,7 @@ interface RelatedItem {
|
|
|
37
60
|
interface UserConfig {
|
|
38
61
|
path: string;
|
|
39
62
|
menu: MenuItem[];
|
|
63
|
+
config?: MarkdownOptions;
|
|
40
64
|
}
|
|
41
65
|
|
|
42
66
|
/**
|
|
@@ -46,8 +70,9 @@ interface UserConfig {
|
|
|
46
70
|
* @param userConfig - The configuration object for the Vite Markdown plugin.
|
|
47
71
|
* @param userConfig.path - The base path prefix to be used for routing or file resolution.
|
|
48
72
|
* @param userConfig.menu - An array of MenuItem objects representing the navigation menu structure.
|
|
73
|
+
* @param userConfig.config - Additional configuration options for the Markdown processing.
|
|
49
74
|
* @returns A Vite Plugin object pre-configured with the provided settings for Markdown processing.
|
|
50
75
|
*/
|
|
51
76
|
declare function viteMdPlugin(userConfig: UserConfig): Plugin;
|
|
52
77
|
|
|
53
|
-
export { type FlatMenu, type FlatMenuEntry, type MenuItem, type MenuNode, type NavItem, type RelatedItem, type UserConfig, viteMdPlugin };
|
|
78
|
+
export { type FlatMenu, type FlatMenuEntry, type MarkdownOptions, type MenuItem, type MenuNode, type NavItem, type RelatedItem, type UserConfig, viteMdPlugin };
|
package/dist/index.mjs
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { join } from 'node:path';
|
|
1
2
|
import MarkdownIt from 'markdown-it';
|
|
2
3
|
import { frontmatterPlugin } from '@md-plugins/md-plugin-frontmatter';
|
|
3
4
|
import { importsPlugin } from '@md-plugins/md-plugin-imports';
|
|
@@ -10,87 +11,6 @@ import { blockquotePlugin } from '@md-plugins/md-plugin-blockquote';
|
|
|
10
11
|
import { tablePlugin } from '@md-plugins/md-plugin-table';
|
|
11
12
|
import { titlePlugin } from '@md-plugins/md-plugin-title';
|
|
12
13
|
import { containersPlugin } from '@md-plugins/md-plugin-containers';
|
|
13
|
-
import { join } from 'node:path';
|
|
14
|
-
|
|
15
|
-
const createContainer = (container, containerType, defaultTitle) => {
|
|
16
|
-
const containerTypeLen = containerType.length;
|
|
17
|
-
return [
|
|
18
|
-
container,
|
|
19
|
-
containerType,
|
|
20
|
-
{
|
|
21
|
-
render(tokens, idx) {
|
|
22
|
-
const token = tokens[idx];
|
|
23
|
-
if (!token) {
|
|
24
|
-
return "";
|
|
25
|
-
}
|
|
26
|
-
const title = token.info.trim().slice(containerTypeLen).trim() || defaultTitle;
|
|
27
|
-
if (containerType === "details") {
|
|
28
|
-
return token.nesting === 1 ? `<details class="markdown-note markdown-note--${containerType}"><summary class="markdown-note__title">${title}</summary>
|
|
29
|
-
` : "</details>\n";
|
|
30
|
-
}
|
|
31
|
-
return token.nesting === 1 ? `<div class="markdown-note markdown-note--${containerType}"><p class="markdown-note__title">${title}</p>
|
|
32
|
-
` : "</div>\n";
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
];
|
|
36
|
-
};
|
|
37
|
-
function createMarkdownRenderer(options = {}) {
|
|
38
|
-
const md2 = new MarkdownIt({
|
|
39
|
-
html: true,
|
|
40
|
-
linkify: true,
|
|
41
|
-
typographer: true,
|
|
42
|
-
...options,
|
|
43
|
-
breaks: true
|
|
44
|
-
});
|
|
45
|
-
md2.use(frontmatterPlugin);
|
|
46
|
-
md2.use(importsPlugin);
|
|
47
|
-
md2.use(titlePlugin);
|
|
48
|
-
md2.use(headersPlugin, { level: [2, 3] });
|
|
49
|
-
const containers = [
|
|
50
|
-
{ type: "tip", defaultTitle: "TIP" },
|
|
51
|
-
{ type: "warning", defaultTitle: "WARNING" },
|
|
52
|
-
{ type: "danger", defaultTitle: "WARNING" },
|
|
53
|
-
{ type: "details", defaultTitle: "Details" }
|
|
54
|
-
];
|
|
55
|
-
md2.use(containersPlugin, containers, createContainer);
|
|
56
|
-
md2.use(blockquotePlugin, { blockquoteClass: "markdown-note" });
|
|
57
|
-
md2.use(tablePlugin, {
|
|
58
|
-
tableClass: "markdown-table",
|
|
59
|
-
tableHeaderClass: "text-left",
|
|
60
|
-
tableToken: "q-markup-table",
|
|
61
|
-
tableAttributes: [
|
|
62
|
-
[":wrap-cells", "true"],
|
|
63
|
-
[":flat", "true"],
|
|
64
|
-
[":bordered", "true"]
|
|
65
|
-
]
|
|
66
|
-
});
|
|
67
|
-
md2.use(codeblocksPlugin, {
|
|
68
|
-
containerComponent: "MarkdownPrerender",
|
|
69
|
-
copyButtonComponent: "MarkdownCopyButton",
|
|
70
|
-
pageScripts: [
|
|
71
|
-
"import MarkdownPrerender from 'src/.q-press/components/MarkdownPrerender'",
|
|
72
|
-
"import MarkdownCopyButton from 'src/.q-press/components/MarkdownCopyButton.vue'"
|
|
73
|
-
]
|
|
74
|
-
});
|
|
75
|
-
md2.use(linkPlugin);
|
|
76
|
-
md2.use(inlinecodePlugin);
|
|
77
|
-
md2.use(imagePlugin);
|
|
78
|
-
return {
|
|
79
|
-
// env: Environment for storing metadata
|
|
80
|
-
render(code, env = {}) {
|
|
81
|
-
const html = md2.render(code, env);
|
|
82
|
-
return {
|
|
83
|
-
html,
|
|
84
|
-
frontmatter: env.frontmatter || {},
|
|
85
|
-
// comes from md_plugin_frontmatter
|
|
86
|
-
title: env.title || "",
|
|
87
|
-
// comes from md_plugin_title
|
|
88
|
-
env
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
};
|
|
92
|
-
}
|
|
93
|
-
const md = createMarkdownRenderer();
|
|
94
14
|
|
|
95
15
|
let prev = null;
|
|
96
16
|
function menuWalk(prefix, menuNodes, node, path, parentName) {
|
|
@@ -207,7 +127,7 @@ function getVueComponent(rendered, code, id, prefix, menu) {
|
|
|
207
127
|
flatMenu = generateFlatMenu(prefix, menu);
|
|
208
128
|
createNav(id, rendered.env, flatMenu);
|
|
209
129
|
}
|
|
210
|
-
const frontmatter = rendered?.frontmatter
|
|
130
|
+
const frontmatter = rendered?.frontmatter;
|
|
211
131
|
if (frontmatter.editLink !== false) {
|
|
212
132
|
frontmatter.editLink = id.substring(id.indexOf("src/markdown/") + 13, id.length - 3);
|
|
213
133
|
}
|
|
@@ -257,10 +177,129 @@ ${pageScripts}
|
|
|
257
177
|
<\/script>`;
|
|
258
178
|
}
|
|
259
179
|
|
|
180
|
+
const createContainer = (container, containerType, defaultTitle, md) => {
|
|
181
|
+
const containerTypeLen = containerType.length;
|
|
182
|
+
return [
|
|
183
|
+
container,
|
|
184
|
+
containerType,
|
|
185
|
+
{
|
|
186
|
+
render(tokens, idx) {
|
|
187
|
+
const token = tokens[idx];
|
|
188
|
+
if (!token) {
|
|
189
|
+
return "";
|
|
190
|
+
}
|
|
191
|
+
const rawTitle = token.info.trim().slice(containerTypeLen).trim() || defaultTitle;
|
|
192
|
+
const titleHtml = md ? md.renderInline(rawTitle) : rawTitle;
|
|
193
|
+
if (containerType === "details") {
|
|
194
|
+
return token.nesting === 1 ? `<details class="markdown-note markdown-note--${containerType}"><summary class="markdown-note__title">${titleHtml}</summary>
|
|
195
|
+
` : "</details>\n";
|
|
196
|
+
}
|
|
197
|
+
return token.nesting === 1 ? `<div class="markdown-note markdown-note--${containerType}"><p class="markdown-note__title">${titleHtml}</p>
|
|
198
|
+
` : "</div>\n";
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
];
|
|
202
|
+
};
|
|
203
|
+
function createMarkdownRenderer(options = {}) {
|
|
204
|
+
const md = new MarkdownIt({
|
|
205
|
+
html: true,
|
|
206
|
+
linkify: true,
|
|
207
|
+
typographer: true,
|
|
208
|
+
...options,
|
|
209
|
+
breaks: true
|
|
210
|
+
});
|
|
211
|
+
md.use(frontmatterPlugin, { ...options });
|
|
212
|
+
md.use(importsPlugin);
|
|
213
|
+
md.use(titlePlugin);
|
|
214
|
+
md.use(headersPlugin, { level: [2, 3], ...options });
|
|
215
|
+
const containers = [
|
|
216
|
+
{ type: "tip", defaultTitle: "TIP" },
|
|
217
|
+
{ type: "warning", defaultTitle: "WARNING" },
|
|
218
|
+
{ type: "danger", defaultTitle: "WARNING" },
|
|
219
|
+
{ type: "details", defaultTitle: "Details" }
|
|
220
|
+
];
|
|
221
|
+
md.use(containersPlugin, containers, createContainer, md);
|
|
222
|
+
md.use(blockquotePlugin, { blockquoteClass: "markdown-note", ...options });
|
|
223
|
+
md.use(tablePlugin, {
|
|
224
|
+
tableClass: "markdown-table",
|
|
225
|
+
tableHeaderClass: "text-left",
|
|
226
|
+
tableToken: "q-markup-table",
|
|
227
|
+
tableAttributes: [
|
|
228
|
+
[":wrap-cells", "true"],
|
|
229
|
+
[":flat", "true"],
|
|
230
|
+
[":bordered", "true"]
|
|
231
|
+
],
|
|
232
|
+
...options
|
|
233
|
+
});
|
|
234
|
+
md.use(codeblocksPlugin, {
|
|
235
|
+
containerComponent: "MarkdownPrerender",
|
|
236
|
+
copyButtonComponent: "MarkdownCopyButton",
|
|
237
|
+
pageScripts: [
|
|
238
|
+
"import MarkdownPrerender from 'src/.q-press/components/MarkdownPrerender'",
|
|
239
|
+
"import MarkdownCopyButton from 'src/.q-press/components/MarkdownCopyButton.vue'"
|
|
240
|
+
],
|
|
241
|
+
...options
|
|
242
|
+
});
|
|
243
|
+
md.use(linkPlugin, { ...options });
|
|
244
|
+
md.use(inlinecodePlugin, { ...options });
|
|
245
|
+
md.use(imagePlugin, { ...options });
|
|
246
|
+
return {
|
|
247
|
+
// env: Environment for storing metadata
|
|
248
|
+
render(code, env = {}) {
|
|
249
|
+
const html = md.render(code, env);
|
|
250
|
+
return {
|
|
251
|
+
html,
|
|
252
|
+
frontmatter: env.frontmatter || {},
|
|
253
|
+
// comes from md_plugin_frontmatter
|
|
254
|
+
title: env.title || "",
|
|
255
|
+
// comes from md_plugin_title
|
|
256
|
+
env
|
|
257
|
+
};
|
|
258
|
+
}
|
|
259
|
+
};
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function flattenOptions(options) {
|
|
263
|
+
const flattened = { ...options };
|
|
264
|
+
if (options.blockquote) {
|
|
265
|
+
Object.assign(flattened, options.blockquote);
|
|
266
|
+
delete flattened.blockquote;
|
|
267
|
+
}
|
|
268
|
+
if (options.codeblocks) {
|
|
269
|
+
Object.assign(flattened, options.codeblocks);
|
|
270
|
+
delete flattened.codeblocks;
|
|
271
|
+
}
|
|
272
|
+
if (options.frontmatter) {
|
|
273
|
+
Object.assign(flattened, options.frontmatter);
|
|
274
|
+
delete flattened.frontmatter;
|
|
275
|
+
}
|
|
276
|
+
if (options.headers && typeof options.headers === "object") {
|
|
277
|
+
Object.assign(flattened, options.headers);
|
|
278
|
+
delete flattened.headers;
|
|
279
|
+
}
|
|
280
|
+
if (options.image) {
|
|
281
|
+
Object.assign(flattened, options.image);
|
|
282
|
+
delete flattened.image;
|
|
283
|
+
}
|
|
284
|
+
if (options.inlinecode) {
|
|
285
|
+
Object.assign(flattened, options.inlinecode);
|
|
286
|
+
delete flattened.inlinecode;
|
|
287
|
+
}
|
|
288
|
+
if (options.link) {
|
|
289
|
+
Object.assign(flattened, options.link);
|
|
290
|
+
delete flattened.link;
|
|
291
|
+
}
|
|
292
|
+
if (options.table) {
|
|
293
|
+
Object.assign(flattened, options.table);
|
|
294
|
+
delete flattened.table;
|
|
295
|
+
}
|
|
296
|
+
return flattened;
|
|
297
|
+
}
|
|
298
|
+
|
|
260
299
|
const markdownLinkRE = /<MarkdownLink /;
|
|
261
300
|
const markdownApiRE = /<MarkdownApi /;
|
|
262
301
|
const markdownTreeRE = /<MarkdownTree /;
|
|
263
|
-
function mdParse(code, id, prefix, menu) {
|
|
302
|
+
function mdParse(code, id, prefix, menu, options = {}) {
|
|
264
303
|
const env = {
|
|
265
304
|
frontmatter: {
|
|
266
305
|
id
|
|
@@ -274,6 +313,8 @@ function mdParse(code, id, prefix, menu) {
|
|
|
274
313
|
if (markdownTreeRE.test(code) === true) {
|
|
275
314
|
env.pageScripts.add("import MarkdownTree from 'src/.q-press/components/MarkdownTree.vue'");
|
|
276
315
|
}
|
|
316
|
+
const flatOptions = flattenOptions(options);
|
|
317
|
+
const md = createMarkdownRenderer(flatOptions);
|
|
277
318
|
const results = md.render(code, env);
|
|
278
319
|
if (env.frontmatter.examples !== undefined) {
|
|
279
320
|
env.pageScripts.add(
|
|
@@ -285,19 +326,18 @@ function mdParse(code, id, prefix, menu) {
|
|
|
285
326
|
}
|
|
286
327
|
const component = getVueComponent(results, code, id, prefix, menu);
|
|
287
328
|
return {
|
|
288
|
-
code: component
|
|
289
|
-
map: null
|
|
290
|
-
// No source map provided
|
|
329
|
+
code: component
|
|
291
330
|
};
|
|
292
331
|
}
|
|
293
332
|
|
|
294
333
|
const mdRE = /\.md$/;
|
|
295
334
|
let globalMenu = [];
|
|
296
335
|
let globalPrefix = "";
|
|
336
|
+
let globalConfig = {};
|
|
297
337
|
function transform(code, id) {
|
|
298
338
|
if (!mdRE.test(id)) return null;
|
|
299
339
|
try {
|
|
300
|
-
const result = mdParse(code, id, globalPrefix, globalMenu);
|
|
340
|
+
const result = mdParse(code, id, globalPrefix, globalMenu, globalConfig);
|
|
301
341
|
return result.code;
|
|
302
342
|
} catch (err) {
|
|
303
343
|
console.error(`Error processing Markdown file: ${id}`, err);
|
|
@@ -330,13 +370,14 @@ const mdPlugins = {
|
|
|
330
370
|
transform,
|
|
331
371
|
hotUpdate
|
|
332
372
|
};
|
|
333
|
-
function viteMdPlugin2(path, menu) {
|
|
373
|
+
function viteMdPlugin2(path, menu, config) {
|
|
334
374
|
globalMenu = menu;
|
|
335
375
|
globalPrefix = path;
|
|
376
|
+
globalConfig = config;
|
|
336
377
|
return mdPlugins;
|
|
337
378
|
}
|
|
338
379
|
function viteMdPlugin(userConfig) {
|
|
339
|
-
return viteMdPlugin2(userConfig.path, userConfig.menu);
|
|
380
|
+
return viteMdPlugin2(userConfig.path, userConfig.menu, userConfig.config || {});
|
|
340
381
|
}
|
|
341
382
|
|
|
342
383
|
export { viteMdPlugin };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@md-plugins/vite-md-plugin",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.27",
|
|
4
4
|
"description": "A very opinionated Vite plugin for @md-plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
@@ -36,18 +36,18 @@
|
|
|
36
36
|
],
|
|
37
37
|
"dependencies": {
|
|
38
38
|
"markdown-it": "^14.1.0",
|
|
39
|
-
"@md-plugins/md-plugin-blockquote": "0.1.0-alpha.
|
|
40
|
-
"@md-plugins/md-plugin-containers": "0.1.0-alpha.
|
|
41
|
-
"@md-plugins/md-plugin-
|
|
42
|
-
"@md-plugins/md-plugin-
|
|
43
|
-
"@md-plugins/md-plugin-
|
|
44
|
-
"@md-plugins/md-plugin-
|
|
45
|
-
"@md-plugins/md-plugin-
|
|
46
|
-
"@md-plugins/md-plugin-
|
|
47
|
-
"@md-plugins/
|
|
48
|
-
"@md-plugins/md-plugin-
|
|
49
|
-
"@md-plugins/md-plugin-
|
|
50
|
-
"@md-plugins/
|
|
39
|
+
"@md-plugins/md-plugin-blockquote": "0.1.0-alpha.27",
|
|
40
|
+
"@md-plugins/md-plugin-containers": "0.1.0-alpha.27",
|
|
41
|
+
"@md-plugins/md-plugin-codeblocks": "0.1.0-alpha.27",
|
|
42
|
+
"@md-plugins/md-plugin-headers": "0.1.0-alpha.27",
|
|
43
|
+
"@md-plugins/md-plugin-imports": "0.1.0-alpha.27",
|
|
44
|
+
"@md-plugins/md-plugin-frontmatter": "0.1.0-alpha.27",
|
|
45
|
+
"@md-plugins/md-plugin-image": "0.1.0-alpha.27",
|
|
46
|
+
"@md-plugins/md-plugin-inlinecode": "0.1.0-alpha.27",
|
|
47
|
+
"@md-plugins/md-plugin-table": "0.1.0-alpha.27",
|
|
48
|
+
"@md-plugins/md-plugin-link": "0.1.0-alpha.27",
|
|
49
|
+
"@md-plugins/md-plugin-title": "0.1.0-alpha.27",
|
|
50
|
+
"@md-plugins/shared": "0.1.0-alpha.27"
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {
|
|
53
53
|
"@types/markdown-it": "^14.1.2",
|