@md-plugins/vite-md-plugin 0.1.0-alpha.1 → 0.1.0-alpha.11

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/LICENSE.md CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2024-present, Jeff Galbraith
3
+ Copyright (c) 2024-present, MD-PLUGINS
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -47,16 +47,16 @@ pnpm add @md-plugins/vite-md-plugin
47
47
  To use the `viteMdPlugin`, configure it in your Vite project:
48
48
 
49
49
  ```js
50
- import { defineConfig } from 'vite';
51
- import vue from '@vitejs/plugin-vue';
52
- import { viteMdPlugin } from 'vite-md-plugin';
50
+ import { defineConfig } from 'vite'
51
+ import vue from '@vitejs/plugin-vue'
52
+ import { viteMdPlugin } from 'vite-md-plugin'
53
53
 
54
- const menu = []; // Define your navigation menu structure here
55
- const basePath = '/docs'; // Base path prefix
54
+ const menu = [] // Define your navigation menu structure here
55
+ const basePath = '/docs' // Base path prefix
56
56
 
57
57
  export default defineConfig({
58
- plugins: [vue(), viteMdPlugin(basePath, menu)],
59
- });
58
+ plugins: [vue(), viteMdPlugin({ path: basePath, menu })],
59
+ })
60
60
  ```
61
61
 
62
62
  ## Quasar Framework Configuration
@@ -67,7 +67,7 @@ If you’re using the Quasar Framework, additional configuration is needed to en
67
67
 
68
68
  ```js
69
69
  import { viteMdPlugin } from '@md-plugins/vite-md-plugin';
70
- import { menu } from './src/assets/menu'; // be sure to create this file
70
+ import { menu } from './src/.q-press/assets/menu'; // be sure to create this file
71
71
 
72
72
  export default defineConfig((ctx) => {
73
73
  // ...
@@ -82,7 +82,13 @@ build: {
82
82
  },
83
83
 
84
84
  vitePlugins: [
85
- viteMdPlugin(ctx.appPaths.srcDir + '/pages', menu),
85
+ [
86
+ viteMdPlugin,
87
+ {
88
+ path: ctx.appPaths.srcDir + '/markdown',
89
+ menu: sidebar as MenuItem[],
90
+ },
91
+ ],
86
92
  // ...
87
93
  ],
88
94
  },
@@ -102,7 +108,7 @@ The `viteMdPlugin` allows you to define a navigation structure that can be updat
102
108
  const menu = [
103
109
  { title: 'Home', path: '/home' },
104
110
  { title: 'About', path: '/about' },
105
- ];
111
+ ]
106
112
  ```
107
113
 
108
114
  This menu is passed as a parameter to the plugin and can be used to build a dynamic sidebar or navigation bar in your application.
@@ -122,16 +128,16 @@ The `menu` parameter should conform to the following structure:
122
128
 
123
129
  ```ts
124
130
  export interface MenuItem {
125
- name: string;
126
- path?: string;
127
- icon?: string;
128
- iconColor?: string;
129
- rightIcon?: string;
130
- rightIconColor?: string;
131
- badge?: string;
132
- children?: MenuItem[];
133
- external?: boolean;
134
- expanded?: boolean;
131
+ name: string
132
+ path?: string
133
+ icon?: string
134
+ iconColor?: string
135
+ rightIcon?: string
136
+ rightIconColor?: string
137
+ badge?: string
138
+ children?: MenuItem[]
139
+ external?: boolean
140
+ expanded?: boolean
135
141
  }
136
142
  ```
137
143
 
@@ -143,6 +149,10 @@ To run the tests for this plugin, use the following command:
143
149
  pnpm test
144
150
  ```
145
151
 
152
+ ## Documentation
153
+
154
+ In case this README falls out of date, please refer to the [documentation](https://md-plugins.netlify.app/vite-plugins/vitemdplugin/overview) for the latest information.
155
+
146
156
  ## License
147
157
 
148
158
  This project is licensed under the MIT License. See the [LICENSE](LICENSE.md) file for details.
package/dist/index.d.mts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Plugin } from 'vite';
2
+
1
3
  interface MenuItem {
2
4
  name: string;
3
5
  path?: string;
@@ -6,7 +8,7 @@ interface MenuItem {
6
8
  rightIcon?: string;
7
9
  rightIconColor?: string;
8
10
  badge?: string;
9
- children?: MenuItem[];
11
+ children?: MenuItem[] | undefined;
10
12
  external?: boolean;
11
13
  expanded?: boolean;
12
14
  }
@@ -32,31 +34,20 @@ interface RelatedItem {
32
34
  category: string;
33
35
  path: string;
34
36
  }
37
+ interface UserConfig {
38
+ path: string;
39
+ menu: MenuItem[];
40
+ }
35
41
 
36
42
  /**
37
- * Transforms markdown content into Vue Single File Component (SFC) format.
43
+ * Creates a Vite plugin for processing Markdown files based on the provided user configuration.
44
+ * This function configures and returns a plugin that transforms Markdown content into Vue Single File Components (SFCs).
38
45
  *
39
- * @param code - The markdown content to be transformed.
40
- * @param id - The identifier (typically the file path) of the markdown file.
41
- * @returns The transformed Vue SFC content, or null if the file is not a markdown file.
42
- * @throws Will throw an error if the markdown transformation process fails.
46
+ * @param userConfig - The configuration object for the Vite Markdown plugin.
47
+ * @param userConfig.path - The base path prefix to be used for routing or file resolution.
48
+ * @param userConfig.menu - An array of MenuItem objects representing the navigation menu structure.
49
+ * @returns A Vite Plugin object pre-configured with the provided settings for Markdown processing.
43
50
  */
44
- declare function transform(code: string, id: string): {
45
- code: string;
46
- map: null;
47
- } | null;
48
- /**
49
- * Creates a Vite plugin for processing Markdown files.
50
- * This plugin transforms Markdown content into Vue Single File Components (SFCs).
51
- *
52
- * @param path - The base path prefix to be used for routing or file resolution.
53
- * @param menu - An array of MenuItem objects representing the navigation menu structure.
54
- * @returns A Vite plugin object with pre-configured settings for Markdown processing.
55
- */
56
- declare function viteMdPlugin(path: string, menu: MenuItem[]): {
57
- name: string;
58
- enforce: string;
59
- transform: typeof transform;
60
- };
51
+ declare function viteMdPlugin(userConfig: UserConfig): Plugin;
61
52
 
62
- export { type FlatMenu, type FlatMenuEntry, type MenuItem, type MenuNode, type NavItem, type RelatedItem, viteMdPlugin };
53
+ export { type FlatMenu, type FlatMenuEntry, type MenuItem, type MenuNode, type NavItem, type RelatedItem, type UserConfig, viteMdPlugin };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
+ import { Plugin } from 'vite';
2
+
1
3
  interface MenuItem {
2
4
  name: string;
3
5
  path?: string;
@@ -6,7 +8,7 @@ interface MenuItem {
6
8
  rightIcon?: string;
7
9
  rightIconColor?: string;
8
10
  badge?: string;
9
- children?: MenuItem[];
11
+ children?: MenuItem[] | undefined;
10
12
  external?: boolean;
11
13
  expanded?: boolean;
12
14
  }
@@ -32,31 +34,20 @@ interface RelatedItem {
32
34
  category: string;
33
35
  path: string;
34
36
  }
37
+ interface UserConfig {
38
+ path: string;
39
+ menu: MenuItem[];
40
+ }
35
41
 
36
42
  /**
37
- * Transforms markdown content into Vue Single File Component (SFC) format.
43
+ * Creates a Vite plugin for processing Markdown files based on the provided user configuration.
44
+ * This function configures and returns a plugin that transforms Markdown content into Vue Single File Components (SFCs).
38
45
  *
39
- * @param code - The markdown content to be transformed.
40
- * @param id - The identifier (typically the file path) of the markdown file.
41
- * @returns The transformed Vue SFC content, or null if the file is not a markdown file.
42
- * @throws Will throw an error if the markdown transformation process fails.
46
+ * @param userConfig - The configuration object for the Vite Markdown plugin.
47
+ * @param userConfig.path - The base path prefix to be used for routing or file resolution.
48
+ * @param userConfig.menu - An array of MenuItem objects representing the navigation menu structure.
49
+ * @returns A Vite Plugin object pre-configured with the provided settings for Markdown processing.
43
50
  */
44
- declare function transform(code: string, id: string): {
45
- code: string;
46
- map: null;
47
- } | null;
48
- /**
49
- * Creates a Vite plugin for processing Markdown files.
50
- * This plugin transforms Markdown content into Vue Single File Components (SFCs).
51
- *
52
- * @param path - The base path prefix to be used for routing or file resolution.
53
- * @param menu - An array of MenuItem objects representing the navigation menu structure.
54
- * @returns A Vite plugin object with pre-configured settings for Markdown processing.
55
- */
56
- declare function viteMdPlugin(path: string, menu: MenuItem[]): {
57
- name: string;
58
- enforce: string;
59
- transform: typeof transform;
60
- };
51
+ declare function viteMdPlugin(userConfig: UserConfig): Plugin;
61
52
 
62
- export { type FlatMenu, type FlatMenuEntry, type MenuItem, type MenuNode, type NavItem, type RelatedItem, viteMdPlugin };
53
+ export { type FlatMenu, type FlatMenuEntry, type MenuItem, type MenuNode, type NavItem, type RelatedItem, type UserConfig, viteMdPlugin };
package/dist/index.mjs CHANGED
@@ -55,7 +55,7 @@ function createMarkdownRenderer(options = {}) {
55
55
  md2.use(containersPlugin, containers, createContainer);
56
56
  md2.use(blockquotePlugin, { blockquoteClass: "markdown-note" });
57
57
  md2.use(tablePlugin, {
58
- tableClass: "markdown-page-table",
58
+ tableClass: "markdown-table",
59
59
  tableHeaderClass: "text-left",
60
60
  tableToken: "q-markup-table",
61
61
  tableAttributes: [
@@ -68,8 +68,8 @@ function createMarkdownRenderer(options = {}) {
68
68
  containerComponent: "MarkdownPrerender",
69
69
  copyButtonComponent: "MarkdownCopyButton",
70
70
  pageScripts: [
71
- "import MarkdownPrerender from 'components/md/MarkdownPrerender'",
72
- "import MarkdownCopyButton from 'components/md/MarkdownCopyButton.vue'"
71
+ "import MarkdownPrerender from 'src/.q-press/components/MarkdownPrerender'",
72
+ "import MarkdownCopyButton from 'src/.q-press/components/MarkdownCopyButton.vue'"
73
73
  ]
74
74
  });
75
75
  md2.use(linkPlugin);
@@ -209,23 +209,18 @@ function getVueComponent(rendered, code, id, prefix, menu) {
209
209
  }
210
210
  const frontmatter = rendered?.frontmatter || {};
211
211
  if (frontmatter.editLink !== false) {
212
- frontmatter.editLink = id.substring(
213
- id.indexOf("src/pages/") + 10,
214
- id.length - 3
215
- );
212
+ frontmatter.editLink = id.substring(id.indexOf("src/markdown/") + 13, id.length - 3);
216
213
  }
217
214
  const title = frontmatter.title || rendered.env.title || rendered.title || "Generic Page";
218
215
  const desc = frontmatter.desc || false;
216
+ const fullscreen = frontmatter.fullscreen || false;
219
217
  const overline = frontmatter.overline || false;
220
- const heading = rendered.env.heading || !!title || false;
221
- const related = frontmatter.related && Array.isArray(frontmatter.related) && frontmatter.related.map(
222
- (entry) => convertToRelated(prefix, flatMenu, entry, id)
223
- ) || false;
218
+ const heading = rendered.env.heading || false;
219
+ const related = frontmatter.related && Array.isArray(frontmatter.related) && frontmatter.related.map((entry) => convertToRelated(prefix, flatMenu, entry, id)) || false;
224
220
  const nav = frontmatter.nav || false;
225
221
  const badge = frontmatter.badge || false;
226
222
  const toc = rendered.env.toc || false;
227
223
  const editLink = frontmatter.editLink || false;
228
- frontmatter.components || false;
229
224
  const scope = frontmatter.scope || false;
230
225
  const examples = frontmatter.examples || false;
231
226
  const { mdContent, userScripts } = splitRenderedContent(rendered.html);
@@ -237,6 +232,7 @@ function getVueComponent(rendered, code, id, prefix, menu) {
237
232
  <markdown-page
238
233
  title="${title}"
239
234
  ${desc !== false ? `desc="${desc}"` : ""}
235
+ ${fullscreen !== false ? "fullscreen" : ""}
240
236
  ${overline !== false ? `overline="${overline}"` : ""}
241
237
  ${badge !== false ? `badge="${badge}"` : ""}
242
238
  ${heading !== false ? "heading" : ""}
@@ -246,7 +242,7 @@ function getVueComponent(rendered, code, id, prefix, menu) {
246
242
  ${nav !== false ? ':nav="nav"' : ""}>${mdContent}</markdown-page>
247
243
  </template>
248
244
  <script setup>
249
- import { copyHeading } from 'components/md/markdown-utils'
245
+ import { copyHeading } from 'src/.q-press/components/markdown-utils'
250
246
  ${examples !== false ? `
251
247
  import { provide } from 'vue'
252
248
  provide('_markdown_examples_', process.env.CLIENT
@@ -272,34 +268,26 @@ function mdParse(code, id, prefix, menu) {
272
268
  },
273
269
  pageScripts: /* @__PURE__ */ new Set()
274
270
  };
275
- env.pageScripts.add(
276
- "import MarkdownPage from 'src/layouts/MarkdownPage.vue'"
277
- );
271
+ env.pageScripts.add("import MarkdownPage from 'src/.q-press/layouts/MarkdownPage.vue'");
278
272
  if (markdownApiRE.test(code) === true) {
279
- env.pageScripts.add(
280
- "import MarkdownApi from 'components/md/MarkdownApi.vue'"
281
- );
273
+ env.pageScripts.add("import MarkdownApi from 'src/.q-press/components/MarkdownApi.vue'");
282
274
  }
283
275
  if (markdownInstallationRE.test(code) === true) {
284
276
  env.pageScripts.add(
285
- "import MarkdownInstallation from 'components/md/MarkdownInstallation.vue'"
277
+ "import MarkdownInstallation from 'src/.q-press/components/MarkdownInstallation.vue'"
286
278
  );
287
279
  }
288
280
  if (markdownTreeRE.test(code) === true) {
289
- env.pageScripts.add(
290
- "import MarkdownTree from 'components/md/MarkdownTree.vue'"
291
- );
281
+ env.pageScripts.add("import MarkdownTree from 'src/.q-press/components/MarkdownTree.vue'");
292
282
  }
293
283
  const results = md.render(code, env);
294
284
  if (env.frontmatter.examples !== void 0) {
295
285
  env.pageScripts.add(
296
- "import MarkdownExample from 'components/md/MarkdownExample.vue'"
286
+ "import MarkdownExample from 'src/.q-press/components/MarkdownExample.vue'"
297
287
  );
298
288
  }
299
289
  if (markdownLinkRE.test(code) === true) {
300
- env.pageScripts.add(
301
- "import MarkdownLink from 'components/md/MarkdownLink.vue'"
302
- );
290
+ env.pageScripts.add("import MarkdownLink from 'src/.q-press/components/MarkdownLink.vue'");
303
291
  }
304
292
  const component = getVueComponent(results, code, id, prefix, menu);
305
293
  return {
@@ -315,7 +303,8 @@ let globalPrefix = "";
315
303
  function transform(code, id) {
316
304
  if (!mdRE.test(id)) return null;
317
305
  try {
318
- return mdParse(code, id, globalPrefix, globalMenu);
306
+ const result = mdParse(code, id, globalPrefix, globalMenu);
307
+ return result.code;
319
308
  } catch (err) {
320
309
  console.error(`Error processing Markdown file: ${id}`, err);
321
310
  throw new Error(
@@ -323,16 +312,37 @@ function transform(code, id) {
323
312
  );
324
313
  }
325
314
  }
315
+ function hotUpdate({
316
+ file,
317
+ server,
318
+ modules,
319
+ timestamp
320
+ }) {
321
+ if (mdRE.test(file)) {
322
+ const invalidatedModules = /* @__PURE__ */ new Set();
323
+ for (const mod of modules) {
324
+ server.moduleGraph.invalidateModule(mod, invalidatedModules, timestamp, true);
325
+ }
326
+ server.ws.send({
327
+ type: "full-reload",
328
+ path: file
329
+ });
330
+ }
331
+ return [];
332
+ }
326
333
  const mdPlugins = {
327
- name: "md-plugins:vitePlugin",
334
+ name: "@md-plugins/vite-md-plugin",
328
335
  enforce: "pre",
329
- // before vue
330
- transform
336
+ transform,
337
+ hotUpdate
331
338
  };
332
- function viteMdPlugin(path, menu) {
339
+ function viteMdPlugin2(path, menu) {
333
340
  globalMenu = menu;
334
341
  globalPrefix = path;
335
342
  return mdPlugins;
336
343
  }
344
+ function viteMdPlugin(userConfig) {
345
+ return viteMdPlugin2(userConfig.path, userConfig.menu);
346
+ }
337
347
 
338
348
  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.1",
3
+ "version": "0.1.0-alpha.11",
4
4
  "description": "A very opinionated Vite plugin for @md-plugins.",
5
5
  "keywords": [
6
6
  "markdown-it",
@@ -34,27 +34,33 @@
34
34
  "files": [
35
35
  "./dist"
36
36
  ],
37
+ "dependencies": {
38
+ "@md-plugins/md-plugin-codeblocks": "0.1.0-alpha.11",
39
+ "@md-plugins/md-plugin-blockquote": "0.1.0-alpha.11",
40
+ "@md-plugins/md-plugin-containers": "0.1.0-alpha.11",
41
+ "@md-plugins/md-plugin-frontmatter": "0.1.0-alpha.11",
42
+ "@md-plugins/md-plugin-headers": "0.1.0-alpha.11",
43
+ "@md-plugins/md-plugin-imports": "0.1.0-alpha.11",
44
+ "@md-plugins/md-plugin-image": "0.1.0-alpha.11",
45
+ "@md-plugins/md-plugin-inlinecode": "0.1.0-alpha.11",
46
+ "@md-plugins/md-plugin-link": "0.1.0-alpha.11",
47
+ "@md-plugins/md-plugin-table": "0.1.0-alpha.11",
48
+ "@md-plugins/shared": "0.1.0-alpha.11",
49
+ "@md-plugins/md-plugin-title": "0.1.0-alpha.11"
50
+ },
37
51
  "devDependencies": {
38
52
  "@types/markdown-it": "^14.1.2",
39
53
  "markdown-it": "^14.1.0",
40
- "@md-plugins/shared": "0.1.0-alpha.1",
41
- "@md-plugins/md-plugin-containers": "0.1.0-alpha.1",
42
- "@md-plugins/md-plugin-headers": "0.1.0-alpha.1",
43
- "@md-plugins/md-plugin-frontmatter": "0.1.0-alpha.1",
44
- "@md-plugins/md-plugin-inlinecode": "0.1.0-alpha.1",
45
- "@md-plugins/md-plugin-imports": "0.1.0-alpha.1",
46
- "@md-plugins/md-plugin-table": "0.1.0-alpha.1",
47
- "@md-plugins/md-plugin-title": "0.1.0-alpha.1",
48
- "@md-plugins/md-plugin-codeblocks": "0.1.0-alpha.1",
49
- "@md-plugins/md-plugin-blockquote": "0.1.0-alpha.1",
50
- "@md-plugins/md-plugin-image": "0.1.0-alpha.1",
51
- "@md-plugins/md-plugin-link": "0.1.0-alpha.1"
54
+ "vite": "^6.0.7"
55
+ },
56
+ "peerDependencies": {
57
+ "markdown-it": "^14.1.0"
52
58
  },
53
59
  "publishConfig": {
54
60
  "access": "public"
55
61
  },
56
62
  "scripts": {
57
63
  "build": "unbuild",
58
- "clean": "rm -rf dist"
64
+ "clean": "rm -rf dist/ node_modules/"
59
65
  }
60
66
  }