@md-plugins/vite-md-plugin 0.1.0-alpha.9 → 0.1.0-beta.1
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 +39 -41
- package/dist/index.d.mts +30 -1
- package/dist/index.d.ts +30 -1
- package/dist/index.mjs +106 -104
- package/package.json +27 -27
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
|
|
@@ -49,7 +51,7 @@ To use the `viteMdPlugin`, configure it in your Vite project:
|
|
|
49
51
|
```js
|
|
50
52
|
import { defineConfig } from 'vite'
|
|
51
53
|
import vue from '@vitejs/plugin-vue'
|
|
52
|
-
import { viteMdPlugin } from 'vite-md-plugin'
|
|
54
|
+
import { viteMdPlugin } from '@md-plugins/vite-md-plugin'
|
|
53
55
|
|
|
54
56
|
const menu = [] // Define your navigation menu structure here
|
|
55
57
|
const basePath = '/docs' // Base path prefix
|
|
@@ -65,38 +67,30 @@ 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
|
|
71
|
-
|
|
72
|
-
export default defineConfig((ctx) => {
|
|
73
|
-
// ...
|
|
74
|
-
```
|
|
70
|
+
- ```js
|
|
71
|
+
import { viteMdPlugin, type MenuItem, type MarkdownOptions } from '@md-plugins/vite-md-plugin'
|
|
72
|
+
import { menu } from './src/assets/menu' // be sure to create this file
|
|
75
73
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
[
|
|
86
|
-
viteMdPlugin,
|
|
87
|
-
{
|
|
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
|
|
80
|
+
},
|
|
81
|
+
vitePlugins: [
|
|
82
|
+
viteMdPlugin({
|
|
88
83
|
path: ctx.appPaths.srcDir + '/markdown',
|
|
89
|
-
menu:
|
|
90
|
-
|
|
84
|
+
menu: menu as MenuItem[],
|
|
85
|
+
// config: myOptions as MarkdownOptions,
|
|
86
|
+
}),
|
|
87
|
+
// ...
|
|
91
88
|
],
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
autoImportVueExtensions: ['vue', 'md'], // Enable auto-import for Markdown extensions
|
|
98
|
-
},
|
|
99
|
-
```
|
|
89
|
+
},
|
|
90
|
+
framework: {
|
|
91
|
+
autoImportVueExtensions: ['vue', 'md'], // Enable auto-import for Markdown extensions
|
|
92
|
+
},
|
|
93
|
+
```
|
|
100
94
|
|
|
101
95
|
2. Ensure that your routes and hash links are compatible with Vue Router's history mode.
|
|
102
96
|
|
|
@@ -106,8 +100,8 @@ The `viteMdPlugin` allows you to define a navigation structure that can be updat
|
|
|
106
100
|
|
|
107
101
|
```js
|
|
108
102
|
const menu = [
|
|
109
|
-
{
|
|
110
|
-
{
|
|
103
|
+
{ name: 'Home', path: '/home' },
|
|
104
|
+
{ name: 'About', path: '/about' },
|
|
111
105
|
]
|
|
112
106
|
```
|
|
113
107
|
|
|
@@ -117,10 +111,10 @@ This menu is passed as a parameter to the plugin and can be used to build a dyna
|
|
|
117
111
|
|
|
118
112
|
The `viteMdPlugin` accepts the following parameters:
|
|
119
113
|
|
|
120
|
-
| Parameter | Type | Description
|
|
121
|
-
| --------- | ---------- |
|
|
122
|
-
| path | string | The base path prefix for routing or file resolution.
|
|
123
|
-
| menu | MenuItem[] | An array representing the navigation menu structure. Each item should have
|
|
114
|
+
| Parameter | Type | Description |
|
|
115
|
+
| --------- | ---------- | ----------------------------------------------------------------------------------------- |
|
|
116
|
+
| path | string | The base path prefix for routing or file resolution. |
|
|
117
|
+
| menu | MenuItem[] | An array representing the navigation menu structure. Each item should have name and path. |
|
|
124
118
|
|
|
125
119
|
## MenuItem Type
|
|
126
120
|
|
|
@@ -149,6 +143,10 @@ To run the tests for this plugin, use the following command:
|
|
|
149
143
|
pnpm test
|
|
150
144
|
```
|
|
151
145
|
|
|
146
|
+
## Documentation
|
|
147
|
+
|
|
148
|
+
In case this README falls out of date, please refer to the [documentation](https://md-plugins.netlify.app/vite-plugins/vite-md-plugin/overview) for the latest information.
|
|
149
|
+
|
|
152
150
|
## License
|
|
153
151
|
|
|
154
152
|
This project is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.
|
package/dist/index.d.mts
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
+
import { Options } from 'markdown-it';
|
|
3
|
+
import { MarkdownItEnv } from '@md-plugins/shared';
|
|
4
|
+
import { BlockquotePluginOptions } from '@md-plugins/md-plugin-blockquote';
|
|
5
|
+
import { CodeblockPluginOptions } from '@md-plugins/md-plugin-codeblocks';
|
|
6
|
+
import { FrontmatterPluginOptions } from '@md-plugins/md-plugin-frontmatter';
|
|
7
|
+
import { HeadersPluginOptions } from '@md-plugins/md-plugin-headers';
|
|
8
|
+
import { ImagePluginOptions } from '@md-plugins/md-plugin-image';
|
|
9
|
+
import { InlineCodePluginOptions } from '@md-plugins/md-plugin-inlinecode';
|
|
10
|
+
import { LinkPluginOptions } from '@md-plugins/md-plugin-link';
|
|
11
|
+
import { TablePluginOptions } from '@md-plugins/md-plugin-table';
|
|
2
12
|
|
|
13
|
+
interface MarkdownOptions extends Options {
|
|
14
|
+
html?: boolean;
|
|
15
|
+
linkify?: boolean;
|
|
16
|
+
typographer?: boolean;
|
|
17
|
+
breaks?: boolean;
|
|
18
|
+
blockquotePlugin?: BlockquotePluginOptions;
|
|
19
|
+
codeblockPlugin?: CodeblockPluginOptions;
|
|
20
|
+
frontmatterPlugin?: FrontmatterPluginOptions;
|
|
21
|
+
headersPlugin?: HeadersPluginOptions | boolean;
|
|
22
|
+
imagePlugin?: ImagePluginOptions;
|
|
23
|
+
inlineCodePlugin?: InlineCodePluginOptions;
|
|
24
|
+
linkPlugin?: LinkPluginOptions;
|
|
25
|
+
tablePlugin?: TablePluginOptions;
|
|
26
|
+
preProcess?: (env: MarkdownItEnv) => void;
|
|
27
|
+
postProcess?: (env: MarkdownItEnv) => void;
|
|
28
|
+
}
|
|
3
29
|
interface MenuItem {
|
|
4
30
|
name: string;
|
|
5
31
|
path?: string;
|
|
@@ -37,6 +63,7 @@ interface RelatedItem {
|
|
|
37
63
|
interface UserConfig {
|
|
38
64
|
path: string;
|
|
39
65
|
menu: MenuItem[];
|
|
66
|
+
config?: MarkdownOptions;
|
|
40
67
|
}
|
|
41
68
|
|
|
42
69
|
/**
|
|
@@ -46,8 +73,10 @@ interface UserConfig {
|
|
|
46
73
|
* @param userConfig - The configuration object for the Vite Markdown plugin.
|
|
47
74
|
* @param userConfig.path - The base path prefix to be used for routing or file resolution.
|
|
48
75
|
* @param userConfig.menu - An array of MenuItem objects representing the navigation menu structure.
|
|
76
|
+
* @param userConfig.config - Additional configuration options for the Markdown processing.
|
|
49
77
|
* @returns A Vite Plugin object pre-configured with the provided settings for Markdown processing.
|
|
50
78
|
*/
|
|
51
79
|
declare function viteMdPlugin(userConfig: UserConfig): Plugin;
|
|
52
80
|
|
|
53
|
-
export {
|
|
81
|
+
export { viteMdPlugin };
|
|
82
|
+
export type { FlatMenu, FlatMenuEntry, MarkdownOptions, MenuItem, MenuNode, NavItem, RelatedItem, UserConfig };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,31 @@
|
|
|
1
1
|
import { Plugin } from 'vite';
|
|
2
|
+
import { Options } from 'markdown-it';
|
|
3
|
+
import { MarkdownItEnv } from '@md-plugins/shared';
|
|
4
|
+
import { BlockquotePluginOptions } from '@md-plugins/md-plugin-blockquote';
|
|
5
|
+
import { CodeblockPluginOptions } from '@md-plugins/md-plugin-codeblocks';
|
|
6
|
+
import { FrontmatterPluginOptions } from '@md-plugins/md-plugin-frontmatter';
|
|
7
|
+
import { HeadersPluginOptions } from '@md-plugins/md-plugin-headers';
|
|
8
|
+
import { ImagePluginOptions } from '@md-plugins/md-plugin-image';
|
|
9
|
+
import { InlineCodePluginOptions } from '@md-plugins/md-plugin-inlinecode';
|
|
10
|
+
import { LinkPluginOptions } from '@md-plugins/md-plugin-link';
|
|
11
|
+
import { TablePluginOptions } from '@md-plugins/md-plugin-table';
|
|
2
12
|
|
|
13
|
+
interface MarkdownOptions extends Options {
|
|
14
|
+
html?: boolean;
|
|
15
|
+
linkify?: boolean;
|
|
16
|
+
typographer?: boolean;
|
|
17
|
+
breaks?: boolean;
|
|
18
|
+
blockquotePlugin?: BlockquotePluginOptions;
|
|
19
|
+
codeblockPlugin?: CodeblockPluginOptions;
|
|
20
|
+
frontmatterPlugin?: FrontmatterPluginOptions;
|
|
21
|
+
headersPlugin?: HeadersPluginOptions | boolean;
|
|
22
|
+
imagePlugin?: ImagePluginOptions;
|
|
23
|
+
inlineCodePlugin?: InlineCodePluginOptions;
|
|
24
|
+
linkPlugin?: LinkPluginOptions;
|
|
25
|
+
tablePlugin?: TablePluginOptions;
|
|
26
|
+
preProcess?: (env: MarkdownItEnv) => void;
|
|
27
|
+
postProcess?: (env: MarkdownItEnv) => void;
|
|
28
|
+
}
|
|
3
29
|
interface MenuItem {
|
|
4
30
|
name: string;
|
|
5
31
|
path?: string;
|
|
@@ -37,6 +63,7 @@ interface RelatedItem {
|
|
|
37
63
|
interface UserConfig {
|
|
38
64
|
path: string;
|
|
39
65
|
menu: MenuItem[];
|
|
66
|
+
config?: MarkdownOptions;
|
|
40
67
|
}
|
|
41
68
|
|
|
42
69
|
/**
|
|
@@ -46,8 +73,10 @@ interface UserConfig {
|
|
|
46
73
|
* @param userConfig - The configuration object for the Vite Markdown plugin.
|
|
47
74
|
* @param userConfig.path - The base path prefix to be used for routing or file resolution.
|
|
48
75
|
* @param userConfig.menu - An array of MenuItem objects representing the navigation menu structure.
|
|
76
|
+
* @param userConfig.config - Additional configuration options for the Markdown processing.
|
|
49
77
|
* @returns A Vite Plugin object pre-configured with the provided settings for Markdown processing.
|
|
50
78
|
*/
|
|
51
79
|
declare function viteMdPlugin(userConfig: UserConfig): Plugin;
|
|
52
80
|
|
|
53
|
-
export {
|
|
81
|
+
export { viteMdPlugin };
|
|
82
|
+
export type { FlatMenu, FlatMenuEntry, MarkdownOptions, MenuItem, MenuNode, NavItem, RelatedItem, UserConfig };
|
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) {
|
|
@@ -245,7 +165,7 @@ function getVueComponent(rendered, code, id, prefix, menu) {
|
|
|
245
165
|
import { copyHeading } from 'src/.q-press/components/markdown-utils'
|
|
246
166
|
${examples !== false ? `
|
|
247
167
|
import { provide } from 'vue'
|
|
248
|
-
provide('_markdown_examples_',
|
|
168
|
+
provide('_markdown_examples_', import.meta.env.QUASAR_CLIENT
|
|
249
169
|
? { name: '${examples}', list: import('examples:${examples}') }
|
|
250
170
|
: { name: '${examples}' })
|
|
251
171
|
` : ""}
|
|
@@ -257,58 +177,139 @@ ${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
|
+
breaks: true,
|
|
209
|
+
...options
|
|
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
|
+
|
|
260
262
|
const markdownLinkRE = /<MarkdownLink /;
|
|
261
263
|
const markdownApiRE = /<MarkdownApi /;
|
|
262
|
-
const markdownInstallationRE = /<MarkdownInstallation /;
|
|
263
264
|
const markdownTreeRE = /<MarkdownTree /;
|
|
264
|
-
function mdParse(code, id, prefix, menu) {
|
|
265
|
+
function mdParse(code, id, prefix, menu, options = {}) {
|
|
265
266
|
const env = {
|
|
266
|
-
frontmatter: {
|
|
267
|
-
id
|
|
268
|
-
},
|
|
267
|
+
frontmatter: { id },
|
|
269
268
|
pageScripts: /* @__PURE__ */ new Set()
|
|
270
269
|
};
|
|
271
270
|
env.pageScripts.add("import MarkdownPage from 'src/.q-press/layouts/MarkdownPage.vue'");
|
|
272
|
-
if (markdownApiRE.test(code)
|
|
271
|
+
if (markdownApiRE.test(code)) {
|
|
273
272
|
env.pageScripts.add("import MarkdownApi from 'src/.q-press/components/MarkdownApi.vue'");
|
|
274
273
|
}
|
|
275
|
-
if (
|
|
276
|
-
env.pageScripts.add(
|
|
277
|
-
"import MarkdownInstallation from 'src/.q-press/components/MarkdownInstallation.vue'"
|
|
278
|
-
);
|
|
279
|
-
}
|
|
280
|
-
if (markdownTreeRE.test(code) === true) {
|
|
274
|
+
if (markdownTreeRE.test(code)) {
|
|
281
275
|
env.pageScripts.add("import MarkdownTree from 'src/.q-press/components/MarkdownTree.vue'");
|
|
282
276
|
}
|
|
277
|
+
if (typeof options.preProcess === "function") {
|
|
278
|
+
options.preProcess(env);
|
|
279
|
+
}
|
|
280
|
+
const md = createMarkdownRenderer(options);
|
|
283
281
|
const results = md.render(code, env);
|
|
284
282
|
if (env.frontmatter.examples !== void 0) {
|
|
285
283
|
env.pageScripts.add(
|
|
286
284
|
"import MarkdownExample from 'src/.q-press/components/MarkdownExample.vue'"
|
|
287
285
|
);
|
|
288
286
|
}
|
|
289
|
-
if (markdownLinkRE.test(code)
|
|
287
|
+
if (markdownLinkRE.test(code)) {
|
|
290
288
|
env.pageScripts.add("import MarkdownLink from 'src/.q-press/components/MarkdownLink.vue'");
|
|
291
289
|
}
|
|
290
|
+
if (typeof options.postProcess === "function") {
|
|
291
|
+
options.postProcess(env);
|
|
292
|
+
}
|
|
292
293
|
const component = getVueComponent(results, code, id, prefix, menu);
|
|
293
|
-
return {
|
|
294
|
-
code: component,
|
|
295
|
-
map: null
|
|
296
|
-
// No source map provided
|
|
297
|
-
};
|
|
294
|
+
return { code: component };
|
|
298
295
|
}
|
|
299
296
|
|
|
300
297
|
const mdRE = /\.md$/;
|
|
301
298
|
let globalMenu = [];
|
|
302
299
|
let globalPrefix = "";
|
|
300
|
+
let globalConfig = {};
|
|
303
301
|
function transform(code, id) {
|
|
304
302
|
if (!mdRE.test(id)) return null;
|
|
305
303
|
try {
|
|
306
|
-
const result = mdParse(code, id, globalPrefix, globalMenu);
|
|
304
|
+
const result = mdParse(code, id, globalPrefix, globalMenu, globalConfig);
|
|
307
305
|
return result.code;
|
|
308
306
|
} catch (err) {
|
|
309
307
|
console.error(`Error processing Markdown file: ${id}`, err);
|
|
310
308
|
throw new Error(
|
|
311
|
-
`Markdown transform failed: ${err instanceof Error ? err.message : String(err)}
|
|
309
|
+
`Markdown transform failed: ${err instanceof Error ? err.message : String(err)}`,
|
|
310
|
+
{
|
|
311
|
+
cause: err
|
|
312
|
+
}
|
|
312
313
|
);
|
|
313
314
|
}
|
|
314
315
|
}
|
|
@@ -336,13 +337,14 @@ const mdPlugins = {
|
|
|
336
337
|
transform,
|
|
337
338
|
hotUpdate
|
|
338
339
|
};
|
|
339
|
-
function viteMdPlugin2(path, menu) {
|
|
340
|
+
function viteMdPlugin2(path, menu, config) {
|
|
340
341
|
globalMenu = menu;
|
|
341
342
|
globalPrefix = path;
|
|
343
|
+
globalConfig = config;
|
|
342
344
|
return mdPlugins;
|
|
343
345
|
}
|
|
344
346
|
function viteMdPlugin(userConfig) {
|
|
345
|
-
return viteMdPlugin2(userConfig.path, userConfig.menu);
|
|
347
|
+
return viteMdPlugin2(userConfig.path, userConfig.menu, userConfig.config || {});
|
|
346
348
|
}
|
|
347
349
|
|
|
348
350
|
export { viteMdPlugin };
|
package/package.json
CHANGED
|
@@ -1,26 +1,31 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@md-plugins/vite-md-plugin",
|
|
3
|
-
"version": "0.1.0-
|
|
3
|
+
"version": "0.1.0-beta.1",
|
|
4
4
|
"description": "A very opinionated Vite plugin for @md-plugins.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"markdown-it",
|
|
7
7
|
"quasarframework",
|
|
8
|
-
"vue",
|
|
9
8
|
"utils",
|
|
10
9
|
"vite",
|
|
11
|
-
"vite-plugin"
|
|
10
|
+
"vite-plugin",
|
|
11
|
+
"vue"
|
|
12
12
|
],
|
|
13
13
|
"homepage": "https://github.com/md-plugins",
|
|
14
14
|
"bugs": {
|
|
15
15
|
"url": "https://github.com/md-plugins/md-plugins/issues"
|
|
16
16
|
},
|
|
17
|
+
"license": "MIT",
|
|
18
|
+
"author": "hawkeye64 <galbraith64@gmail.com>",
|
|
17
19
|
"repository": {
|
|
18
20
|
"type": "git",
|
|
19
21
|
"url": "git+https://github.com/md-plugins/md-plugins.git"
|
|
20
22
|
},
|
|
21
|
-
"
|
|
22
|
-
|
|
23
|
+
"files": [
|
|
24
|
+
"./dist"
|
|
25
|
+
],
|
|
23
26
|
"type": "module",
|
|
27
|
+
"module": "./dist/index.mjs",
|
|
28
|
+
"types": "./dist/index.d.ts",
|
|
24
29
|
"exports": {
|
|
25
30
|
".": {
|
|
26
31
|
"import": {
|
|
@@ -29,36 +34,31 @@
|
|
|
29
34
|
}
|
|
30
35
|
}
|
|
31
36
|
},
|
|
32
|
-
"
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
"./dist"
|
|
36
|
-
],
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"access": "public"
|
|
39
|
+
},
|
|
37
40
|
"dependencies": {
|
|
38
|
-
"
|
|
39
|
-
"@md-plugins/md-plugin-
|
|
40
|
-
"@md-plugins/md-plugin-
|
|
41
|
-
"@md-plugins/md-plugin-headers": "0.1.0-
|
|
42
|
-
"@md-plugins/md-plugin-
|
|
43
|
-
"@md-plugins/md-plugin-image": "0.1.0-
|
|
44
|
-
"@md-plugins/md-plugin-
|
|
45
|
-
"@md-plugins/md-plugin-link": "0.1.0-
|
|
46
|
-
"@md-plugins/md-plugin-
|
|
47
|
-
"@md-plugins/
|
|
48
|
-
"@md-plugins/
|
|
49
|
-
"@md-plugins/md-plugin-
|
|
41
|
+
"markdown-it": "^14.1.1",
|
|
42
|
+
"@md-plugins/md-plugin-blockquote": "0.1.0-beta.1",
|
|
43
|
+
"@md-plugins/md-plugin-frontmatter": "0.1.0-beta.1",
|
|
44
|
+
"@md-plugins/md-plugin-headers": "0.1.0-beta.1",
|
|
45
|
+
"@md-plugins/md-plugin-imports": "0.1.0-beta.1",
|
|
46
|
+
"@md-plugins/md-plugin-image": "0.1.0-beta.1",
|
|
47
|
+
"@md-plugins/md-plugin-inlinecode": "0.1.0-beta.1",
|
|
48
|
+
"@md-plugins/md-plugin-link": "0.1.0-beta.1",
|
|
49
|
+
"@md-plugins/md-plugin-title": "0.1.0-beta.1",
|
|
50
|
+
"@md-plugins/shared": "0.1.0-beta.1",
|
|
51
|
+
"@md-plugins/md-plugin-containers": "0.1.0-beta.1",
|
|
52
|
+
"@md-plugins/md-plugin-table": "0.1.0-beta.1",
|
|
53
|
+
"@md-plugins/md-plugin-codeblocks": "0.1.0-beta.1"
|
|
50
54
|
},
|
|
51
55
|
"devDependencies": {
|
|
52
56
|
"@types/markdown-it": "^14.1.2",
|
|
53
|
-
"
|
|
54
|
-
"vite": "^6.0.7"
|
|
57
|
+
"vite": "^8.0.12"
|
|
55
58
|
},
|
|
56
59
|
"peerDependencies": {
|
|
57
60
|
"markdown-it": "^14.1.0"
|
|
58
61
|
},
|
|
59
|
-
"publishConfig": {
|
|
60
|
-
"access": "public"
|
|
61
|
-
},
|
|
62
62
|
"scripts": {
|
|
63
63
|
"build": "unbuild",
|
|
64
64
|
"clean": "rm -rf dist/ node_modules/"
|