@nuxtjs/mdc 0.2.6 → 0.2.7
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 +1 -1
- package/dist/module.mjs +9 -6
- package/dist/runtime/components/MDCRenderer.vue +1 -1
- package/dist/runtime/parser/index.mjs +3 -4
- package/dist/runtime/shiki/highlighter.mjs +17 -15
- package/dist/runtime/shiki/index.d.ts +1 -1
- package/dist/runtime/shiki/index.mjs +1 -0
- package/package.json +2 -2
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createResolver, extendViteConfig, defineNuxtModule, addTemplate, addComponent, addImports, addComponentsDir
|
|
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 || resolver.resolve("./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 "#
|
|
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 (
|
|
59
|
-
node.children.
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
text
|
|
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
|
}
|
|
@@ -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.
|
|
3
|
+
"version": "0.2.7",
|
|
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.
|
|
61
|
+
"scule": "^1.1.0",
|
|
62
62
|
"shikiji": "^0.6.10",
|
|
63
63
|
"ufo": "^1.3.1",
|
|
64
64
|
"unified": "^11.0.3",
|