@nuxtjs/mdc 0.2.6 → 0.2.8

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/dist/module.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@nuxtjs/mdc",
3
3
  "configKey": "mdc",
4
- "version": "0.2.6"
4
+ "version": "0.2.8"
5
5
  }
package/dist/module.mjs CHANGED
@@ -1,4 +1,4 @@
1
- import { createResolver, extendViteConfig, defineNuxtModule, addTemplate, addComponent, addImports, addComponentsDir, addServerHandler } from '@nuxt/kit';
1
+ import { createResolver, extendViteConfig, defineNuxtModule, addServerHandler, addTemplate, addComponent, addImports, addComponentsDir } from '@nuxt/kit';
2
2
  import fs from 'fs';
3
3
  import { pascalCase } from 'scule';
4
4
  import { defu } from 'defu';
@@ -132,6 +132,14 @@ const module = defineNuxtModule({
132
132
  "hast-util-raw"
133
133
  );
134
134
  });
135
+ if (options.highlight) {
136
+ nuxt.options.nitro.experimental = nuxt.options.nitro.experimental || {};
137
+ nuxt.options.nitro.experimental.wasm = true;
138
+ addServerHandler({ route: "/api/_mdc/highlight", handler: resolver.resolve("./runtime/shiki/event-handler") });
139
+ options.rehypePlugins = options.rehypePlugins || {};
140
+ options.rehypePlugins.highlight = options.rehypePlugins.highlight || {};
141
+ options.rehypePlugins.highlight.src = options.rehypePlugins.highlight.src || await resolver.resolvePath("./runtime/shiki/index");
142
+ }
135
143
  const { dst: templatePath } = addTemplate({ filename: "mdc-imports.mjs", getContents: mdcImportTemplate, options, write: true });
136
144
  nuxt.options.alias["#mdc-imports"] = process.env.NODE_ENV === "development" ? pathToFileURL(templatePath).href : templatePath;
137
145
  nuxt.options.nitro.alias = nuxt.options.nitro.alias || {};
@@ -148,11 +156,6 @@ const module = defineNuxtModule({
148
156
  global: true
149
157
  });
150
158
  }
151
- if (options.highlight) {
152
- nuxt.options.nitro.experimental = nuxt.options.nitro.experimental || {};
153
- nuxt.options.nitro.experimental.wasm = true;
154
- addServerHandler({ route: "/api/_mdc/highlight", handler: resolver.resolve("./runtime/shiki/event-handler") });
155
- }
156
159
  extendViteConfig((config) => {
157
160
  config.optimizeDeps = config.optimizeDeps || {};
158
161
  config.optimizeDeps.exclude = config.optimizeDeps.exclude || [];
@@ -3,7 +3,7 @@ import { h, resolveComponent, Text, defineComponent, toRaw, computed } from "vue
3
3
  import destr from "destr";
4
4
  import { kebabCase, pascalCase } from "scule";
5
5
  import { find, html } from "property-information";
6
- import { useRoute, useRuntimeConfig } from "#app";
6
+ import { useRoute, useRuntimeConfig } from "#imports";
7
7
  import htmlTags from "../parser/utils/html-tags-list";
8
8
  const DEFAULT_SLOT = "default";
9
9
  const rxOn = /^@|^v-on:/;
@@ -6,7 +6,6 @@ import { defu } from "defu";
6
6
  import { useProcessorPlugins } from "./utils/plugins.mjs";
7
7
  import { compileHast } from "./compiler.mjs";
8
8
  import { defaults } from "./options.mjs";
9
- import { rehypeShiki } from "../shiki/index.mjs";
10
9
  import { generateToc } from "./toc.mjs";
11
10
  import { nodeTextContent } from "../utils/node.mjs";
12
11
  let moduleOptions;
@@ -22,14 +21,14 @@ export const parseMarkdown = async (md, opts = {}) => {
22
21
  rehype: { plugins: moduleOptions?.rehypePlugins },
23
22
  highlight: moduleOptions?.highlight
24
23
  }, defaults);
24
+ if (options.rehype?.plugins?.highlight) {
25
+ options.rehype.plugins.highlight.options = options.highlight || {};
26
+ }
25
27
  const { content, data: frontmatter } = await parseFrontMatter(md);
26
28
  const processor = unified();
27
29
  processor.use(remarkParse);
28
30
  await useProcessorPlugins(processor, options.remark?.plugins);
29
31
  processor.use(remark2rehype, options.rehype?.options);
30
- if (options.highlight) {
31
- processor.use(rehypeShiki, options.highlight);
32
- }
33
32
  await useProcessorPlugins(processor, options.rehype?.plugins);
34
33
  processor.use(compileHast);
35
34
  const processedFile = await processor.process({ value: content, data: frontmatter });
@@ -55,21 +55,23 @@ export const useShikiHighlighter = createSingleton((opts) => {
55
55
  node.properties.class = (node.properties.class || "") + " highlight";
56
56
  }
57
57
  node.properties.line = line;
58
- if (node.children.length === 0) {
59
- node.children.push({
60
- type: "element",
61
- tagName: "span",
62
- properties: {
63
- emptyLinePlaceholder: true
64
- },
65
- children: [{ type: "text", value: "" }]
66
- });
67
- }
68
- const last = node.children.at(-1);
69
- if (last?.type === "element" && last.tagName === "span") {
70
- const text = last.children.at(-1);
71
- if (text?.type === "text")
72
- text.value += "\n";
58
+ if (code?.includes("\n")) {
59
+ if (node.children.length === 0) {
60
+ node.children.push({
61
+ type: "element",
62
+ tagName: "span",
63
+ properties: {
64
+ emptyLinePlaceholder: true
65
+ },
66
+ children: [{ type: "text", value: "" }]
67
+ });
68
+ }
69
+ const last = node.children.at(-1);
70
+ if (last?.type === "element" && last.tagName === "span") {
71
+ const text = last.children.at(-1);
72
+ if (text?.type === "text")
73
+ text.value += "\n";
74
+ }
73
75
  }
74
76
  }
75
77
  }
@@ -4,5 +4,5 @@ interface RehypeShikiOption {
4
4
  theme?: Theme;
5
5
  highlighter?: Highlighter;
6
6
  }
7
+ export default rehypeShiki;
7
8
  export declare function rehypeShiki(opts?: RehypeShikiOption): (tree: Root) => Promise<void>;
8
- export {};
@@ -29,6 +29,7 @@ const defaults = {
29
29
  return Promise.resolve({ tree: [{ type: "text", value: code }], className: "", style: "" });
30
30
  }
31
31
  };
32
+ export default rehypeShiki;
32
33
  export function rehypeShiki(opts = {}) {
33
34
  const options = { ...defaults, ...opts };
34
35
  return async (tree) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nuxtjs/mdc",
3
- "version": "0.2.6",
3
+ "version": "0.2.8",
4
4
  "description": "Nuxt MDC module",
5
5
  "repository": "nuxt-modules/mdc",
6
6
  "license": "MIT",
@@ -58,7 +58,7 @@
58
58
  "remark-mdc": "^2.1.0",
59
59
  "remark-parse": "^10.0.2",
60
60
  "remark-rehype": "^10.1.0",
61
- "scule": "^1.0.0",
61
+ "scule": "^1.1.0",
62
62
  "shikiji": "^0.6.10",
63
63
  "ufo": "^1.3.1",
64
64
  "unified": "^11.0.3",
@@ -71,7 +71,7 @@
71
71
  "@nuxt/module-builder": "^0.5.2",
72
72
  "@nuxt/schema": "^3.8.0",
73
73
  "@nuxt/test-utils": "^3.8.0",
74
- "@nuxthq/ui": "^2.7.0",
74
+ "@nuxt/ui": "^2.10.0",
75
75
  "@types/mdurl": "^1.0.4",
76
76
  "@types/node": "^20.8.9",
77
77
  "changelogen": "^0.5.5",