@md-plugins/vite-md-plugin 0.1.0-alpha.26 → 0.1.0-alpha.28

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 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
@@ -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'; // be sure to create this file
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
- ```js
77
- build: {
78
- vueRouterMode: 'history', // Required for proper hash link handling
79
-
80
- viteVuePluginOptions: {
81
- include: [/\.(vue|md)$/], // Include Markdown files
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
- framework: {
97
- autoImportVueExtensions: ['vue', 'md'], // Enable auto-import for Markdown extensions
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,88 +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, md2) => {
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 rawTitle = token.info.trim().slice(containerTypeLen).trim() || defaultTitle;
27
- const titleHtml = md2 ? md2.renderInline(rawTitle) : rawTitle;
28
- if (containerType === "details") {
29
- return token.nesting === 1 ? `<details class="markdown-note markdown-note--${containerType}"><summary class="markdown-note__title">${titleHtml}</summary>
30
- ` : "</details>\n";
31
- }
32
- return token.nesting === 1 ? `<div class="markdown-note markdown-note--${containerType}"><p class="markdown-note__title">${titleHtml}</p>
33
- ` : "</div>\n";
34
- }
35
- }
36
- ];
37
- };
38
- function createMarkdownRenderer(options = {}) {
39
- const md2 = new MarkdownIt({
40
- html: true,
41
- linkify: true,
42
- typographer: true,
43
- ...options,
44
- breaks: true
45
- });
46
- md2.use(frontmatterPlugin);
47
- md2.use(importsPlugin);
48
- md2.use(titlePlugin);
49
- md2.use(headersPlugin, { level: [2, 3] });
50
- const containers = [
51
- { type: "tip", defaultTitle: "TIP" },
52
- { type: "warning", defaultTitle: "WARNING" },
53
- { type: "danger", defaultTitle: "WARNING" },
54
- { type: "details", defaultTitle: "Details" }
55
- ];
56
- md2.use(containersPlugin, containers, createContainer, md2);
57
- md2.use(blockquotePlugin, { blockquoteClass: "markdown-note" });
58
- md2.use(tablePlugin, {
59
- tableClass: "markdown-table",
60
- tableHeaderClass: "text-left",
61
- tableToken: "q-markup-table",
62
- tableAttributes: [
63
- [":wrap-cells", "true"],
64
- [":flat", "true"],
65
- [":bordered", "true"]
66
- ]
67
- });
68
- md2.use(codeblocksPlugin, {
69
- containerComponent: "MarkdownPrerender",
70
- copyButtonComponent: "MarkdownCopyButton",
71
- pageScripts: [
72
- "import MarkdownPrerender from 'src/.q-press/components/MarkdownPrerender'",
73
- "import MarkdownCopyButton from 'src/.q-press/components/MarkdownCopyButton.vue'"
74
- ]
75
- });
76
- md2.use(linkPlugin);
77
- md2.use(inlinecodePlugin);
78
- md2.use(imagePlugin);
79
- return {
80
- // env: Environment for storing metadata
81
- render(code, env = {}) {
82
- const html = md2.render(code, env);
83
- return {
84
- html,
85
- frontmatter: env.frontmatter || {},
86
- // comes from md_plugin_frontmatter
87
- title: env.title || "",
88
- // comes from md_plugin_title
89
- env
90
- };
91
- }
92
- };
93
- }
94
- const md = createMarkdownRenderer();
95
14
 
96
15
  let prev = null;
97
16
  function menuWalk(prefix, menuNodes, node, path, parentName) {
@@ -208,7 +127,7 @@ function getVueComponent(rendered, code, id, prefix, menu) {
208
127
  flatMenu = generateFlatMenu(prefix, menu);
209
128
  createNav(id, rendered.env, flatMenu);
210
129
  }
211
- const frontmatter = rendered?.frontmatter || {};
130
+ const frontmatter = rendered?.frontmatter;
212
131
  if (frontmatter.editLink !== false) {
213
132
  frontmatter.editLink = id.substring(id.indexOf("src/markdown/") + 13, id.length - 3);
214
133
  }
@@ -258,10 +177,129 @@ ${pageScripts}
258
177
  <\/script>`;
259
178
  }
260
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
+
261
299
  const markdownLinkRE = /<MarkdownLink /;
262
300
  const markdownApiRE = /<MarkdownApi /;
263
301
  const markdownTreeRE = /<MarkdownTree /;
264
- function mdParse(code, id, prefix, menu) {
302
+ function mdParse(code, id, prefix, menu, options = {}) {
265
303
  const env = {
266
304
  frontmatter: {
267
305
  id
@@ -275,6 +313,8 @@ function mdParse(code, id, prefix, menu) {
275
313
  if (markdownTreeRE.test(code) === true) {
276
314
  env.pageScripts.add("import MarkdownTree from 'src/.q-press/components/MarkdownTree.vue'");
277
315
  }
316
+ const flatOptions = flattenOptions(options);
317
+ const md = createMarkdownRenderer(flatOptions);
278
318
  const results = md.render(code, env);
279
319
  if (env.frontmatter.examples !== undefined) {
280
320
  env.pageScripts.add(
@@ -286,19 +326,18 @@ function mdParse(code, id, prefix, menu) {
286
326
  }
287
327
  const component = getVueComponent(results, code, id, prefix, menu);
288
328
  return {
289
- code: component,
290
- map: null
291
- // No source map provided
329
+ code: component
292
330
  };
293
331
  }
294
332
 
295
333
  const mdRE = /\.md$/;
296
334
  let globalMenu = [];
297
335
  let globalPrefix = "";
336
+ let globalConfig = {};
298
337
  function transform(code, id) {
299
338
  if (!mdRE.test(id)) return null;
300
339
  try {
301
- const result = mdParse(code, id, globalPrefix, globalMenu);
340
+ const result = mdParse(code, id, globalPrefix, globalMenu, globalConfig);
302
341
  return result.code;
303
342
  } catch (err) {
304
343
  console.error(`Error processing Markdown file: ${id}`, err);
@@ -331,13 +370,14 @@ const mdPlugins = {
331
370
  transform,
332
371
  hotUpdate
333
372
  };
334
- function viteMdPlugin2(path, menu) {
373
+ function viteMdPlugin2(path, menu, config) {
335
374
  globalMenu = menu;
336
375
  globalPrefix = path;
376
+ globalConfig = config;
337
377
  return mdPlugins;
338
378
  }
339
379
  function viteMdPlugin(userConfig) {
340
- return viteMdPlugin2(userConfig.path, userConfig.menu);
380
+ return viteMdPlugin2(userConfig.path, userConfig.menu, userConfig.config || {});
341
381
  }
342
382
 
343
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.26",
3
+ "version": "0.1.0-alpha.28",
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.26",
40
- "@md-plugins/md-plugin-codeblocks": "0.1.0-alpha.26",
41
- "@md-plugins/md-plugin-containers": "0.1.0-alpha.26",
42
- "@md-plugins/md-plugin-frontmatter": "0.1.0-alpha.26",
43
- "@md-plugins/md-plugin-headers": "0.1.0-alpha.26",
44
- "@md-plugins/md-plugin-image": "0.1.0-alpha.26",
45
- "@md-plugins/md-plugin-inlinecode": "0.1.0-alpha.26",
46
- "@md-plugins/md-plugin-link": "0.1.0-alpha.26",
47
- "@md-plugins/md-plugin-imports": "0.1.0-alpha.26",
48
- "@md-plugins/md-plugin-table": "0.1.0-alpha.26",
49
- "@md-plugins/shared": "0.1.0-alpha.26",
50
- "@md-plugins/md-plugin-title": "0.1.0-alpha.26"
39
+ "@md-plugins/md-plugin-blockquote": "0.1.0-alpha.28",
40
+ "@md-plugins/md-plugin-codeblocks": "0.1.0-alpha.28",
41
+ "@md-plugins/md-plugin-containers": "0.1.0-alpha.28",
42
+ "@md-plugins/md-plugin-frontmatter": "0.1.0-alpha.28",
43
+ "@md-plugins/md-plugin-headers": "0.1.0-alpha.28",
44
+ "@md-plugins/md-plugin-image": "0.1.0-alpha.28",
45
+ "@md-plugins/md-plugin-imports": "0.1.0-alpha.28",
46
+ "@md-plugins/md-plugin-table": "0.1.0-alpha.28",
47
+ "@md-plugins/md-plugin-title": "0.1.0-alpha.28",
48
+ "@md-plugins/md-plugin-link": "0.1.0-alpha.28",
49
+ "@md-plugins/md-plugin-inlinecode": "0.1.0-alpha.28",
50
+ "@md-plugins/shared": "0.1.0-alpha.28"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/markdown-it": "^14.1.2",