@nuxtjs/mdc 0.2.9 → 0.3.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/dist/module.json +1 -1
- package/dist/module.mjs +17 -4
- package/dist/runtime/components/MDCRenderer.vue.d.ts +2 -2
- package/dist/runtime/parser/compiler.mjs +1 -1
- package/dist/runtime/parser/utils/props.d.ts +1 -3
- package/dist/runtime/parser/utils/props.mjs +8 -2
- package/dist/runtime/shiki/event-handler.mjs +3 -6
- package/dist/runtime/shiki/highlighter.d.ts +1 -1
- package/dist/runtime/shiki/highlighter.mjs +45 -26
- package/dist/types.d.mts +2 -2
- package/package.json +24 -22
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createResolver, extendViteConfig, defineNuxtModule, addServerHandler, addTemplate, addComponent, addImports, addServerImports, addComponentsDir } from '@nuxt/kit';
|
|
1
|
+
import { createResolver, extendViteConfig, defineNuxtModule, useNitro, addServerHandler, addTemplate, addComponent, addImports, addServerImports, addComponentsDir } from '@nuxt/kit';
|
|
2
2
|
import fs from 'fs';
|
|
3
3
|
import { pascalCase } from 'scule';
|
|
4
4
|
import { defu } from 'defu';
|
|
@@ -123,7 +123,7 @@ const module = defineNuxtModule({
|
|
|
123
123
|
} : {}
|
|
124
124
|
});
|
|
125
125
|
nuxt.hook("vite:extendConfig", (viteConfig) => {
|
|
126
|
-
const optimizeList = ["
|
|
126
|
+
const optimizeList = ["debug", "flat", "node-emoji", "extend", "hast-util-raw"];
|
|
127
127
|
viteConfig.optimizeDeps ||= {};
|
|
128
128
|
viteConfig.optimizeDeps.include ||= [];
|
|
129
129
|
const list = viteConfig.optimizeDeps.include;
|
|
@@ -134,8 +134,21 @@ const module = defineNuxtModule({
|
|
|
134
134
|
});
|
|
135
135
|
});
|
|
136
136
|
if (options.highlight) {
|
|
137
|
-
nuxt.
|
|
138
|
-
|
|
137
|
+
nuxt.hook("ready", () => {
|
|
138
|
+
const nitro = useNitro();
|
|
139
|
+
if (!nitro.options.experimental?.wasm) {
|
|
140
|
+
nitro.options.externals = nitro.options.externals || {};
|
|
141
|
+
nitro.options.externals.inline = nitro.options.externals.inline || [];
|
|
142
|
+
nitro.options.externals.inline.push((id) => id.endsWith(".wasm"));
|
|
143
|
+
nitro.hooks.hook("rollup:before", async (_, rollupConfig) => {
|
|
144
|
+
const { rollup: unwasm } = await import('unwasm/plugin');
|
|
145
|
+
rollupConfig.plugins = rollupConfig.plugins || [];
|
|
146
|
+
rollupConfig.plugins.push(unwasm({
|
|
147
|
+
...nitro.options.wasm
|
|
148
|
+
}));
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
});
|
|
139
152
|
addServerHandler({ route: "/api/_mdc/highlight", handler: resolver.resolve("./runtime/shiki/event-handler") });
|
|
140
153
|
options.rehypePlugins = options.rehypePlugins || {};
|
|
141
154
|
options.rehypePlugins.highlight = options.rehypePlugins.highlight || {};
|
|
@@ -39,7 +39,7 @@ declare const _default: DefineComponent<{
|
|
|
39
39
|
}, {
|
|
40
40
|
tags: any;
|
|
41
41
|
contentKey: import("vue").ComputedRef<string>;
|
|
42
|
-
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").
|
|
42
|
+
}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
43
43
|
/**
|
|
44
44
|
* Content to render
|
|
45
45
|
*/
|
|
@@ -76,8 +76,8 @@ declare const _default: DefineComponent<{
|
|
|
76
76
|
default: () => {};
|
|
77
77
|
};
|
|
78
78
|
}>>, {
|
|
79
|
-
data: Record<string, any>;
|
|
80
79
|
tag: string | boolean;
|
|
80
|
+
data: Record<string, any>;
|
|
81
81
|
prose: boolean;
|
|
82
82
|
components: Record<string, string | DefineComponent<any, any, any>>;
|
|
83
83
|
}, {}>;
|
|
@@ -42,7 +42,7 @@ export function compileHast() {
|
|
|
42
42
|
return {
|
|
43
43
|
type: "element",
|
|
44
44
|
tag: node.tagName,
|
|
45
|
-
props: validateProps(node.properties),
|
|
45
|
+
props: validateProps(node.tagName, node.properties),
|
|
46
46
|
children: node.children.map((child) => compileToJSON(child, node)).filter(Boolean)
|
|
47
47
|
};
|
|
48
48
|
}
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
export declare const unsafeLinkPrefix: string[];
|
|
2
2
|
export declare const validateProp: (attribute: string, value: string) => boolean;
|
|
3
|
-
export declare const validateProps: (props?: Record<string, any>) =>
|
|
4
|
-
[k: string]: any;
|
|
5
|
-
};
|
|
3
|
+
export declare const validateProps: (type: string, props?: Record<string, any>) => Record<string, any>;
|
|
@@ -17,11 +17,11 @@ export const validateProp = (attribute, value) => {
|
|
|
17
17
|
}
|
|
18
18
|
return true;
|
|
19
19
|
};
|
|
20
|
-
export const validateProps = (props) => {
|
|
20
|
+
export const validateProps = (type, props) => {
|
|
21
21
|
if (!props) {
|
|
22
22
|
return {};
|
|
23
23
|
}
|
|
24
|
-
|
|
24
|
+
props = Object.fromEntries(
|
|
25
25
|
Object.entries(props).filter(([name, value]) => {
|
|
26
26
|
const isValid = validateProp(name, value);
|
|
27
27
|
if (!isValid) {
|
|
@@ -30,4 +30,10 @@ export const validateProps = (props) => {
|
|
|
30
30
|
return isValid;
|
|
31
31
|
})
|
|
32
32
|
);
|
|
33
|
+
if (type === "pre") {
|
|
34
|
+
if (typeof props.highlights === "string") {
|
|
35
|
+
props.highlights = props.highlights.split(" ").map((i) => parseInt(i));
|
|
36
|
+
}
|
|
37
|
+
}
|
|
38
|
+
return props;
|
|
33
39
|
};
|
|
@@ -4,12 +4,9 @@ import { useShikiHighlighter } from "./highlighter.mjs";
|
|
|
4
4
|
import { useRuntimeConfig } from "#imports";
|
|
5
5
|
export default lazyEventHandler(async () => {
|
|
6
6
|
const { highlight } = useRuntimeConfig().mdc;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
} catch {
|
|
11
|
-
await loadWasm({ data: await import("shikiji/wasm").then((r) => r.getWasmInlined()).then((r) => r.data) });
|
|
12
|
-
}
|
|
7
|
+
await loadWasm(
|
|
8
|
+
(imports) => import("shikiji/onig.wasm").then((mod) => mod.default(imports)).then((exports) => ({ exports }))
|
|
9
|
+
);
|
|
13
10
|
const shiki = useShikiHighlighter(highlight);
|
|
14
11
|
return eventHandler(async (event) => {
|
|
15
12
|
const { code, lang, theme: themeString, highlights: highlightsString } = getQuery(event);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { type BuiltinLanguage } from 'shikiji';
|
|
2
1
|
import type { HighlightResult, HighlighterOptions, Theme } from './types';
|
|
2
|
+
import type { BuiltinLanguage } from 'shikiji';
|
|
3
3
|
export declare const useShikiHighlighter: (opts?: any) => {
|
|
4
4
|
getHighlightedAST: (code: string, lang: BuiltinLanguage, theme: Theme, opts?: Partial<HighlighterOptions>) => Promise<HighlightResult>;
|
|
5
5
|
};
|
|
@@ -1,4 +1,10 @@
|
|
|
1
|
-
import { getHighlighter } from "shikiji";
|
|
1
|
+
import { getHighlighter, addClassToHast } from "shikiji";
|
|
2
|
+
import {
|
|
3
|
+
transformerNotationDiff,
|
|
4
|
+
transformerNotationErrorLevel,
|
|
5
|
+
transformerNotationFocus,
|
|
6
|
+
transformerNotationHighlight
|
|
7
|
+
} from "shikiji-transformers";
|
|
2
8
|
export const useShikiHighlighter = createSingleton((opts) => {
|
|
3
9
|
const { theme, preload, wrapperStyle } = opts || {};
|
|
4
10
|
let promise;
|
|
@@ -32,6 +38,12 @@ export const useShikiHighlighter = createSingleton((opts) => {
|
|
|
32
38
|
}
|
|
33
39
|
return promise;
|
|
34
40
|
};
|
|
41
|
+
const transformers = [
|
|
42
|
+
transformerNotationDiff(),
|
|
43
|
+
transformerNotationFocus(),
|
|
44
|
+
transformerNotationHighlight(),
|
|
45
|
+
transformerNotationErrorLevel()
|
|
46
|
+
];
|
|
35
47
|
const getHighlightedAST = async (code, lang, theme2, opts2) => {
|
|
36
48
|
try {
|
|
37
49
|
const highlighter = await getShikiHighlighter();
|
|
@@ -56,34 +68,41 @@ export const useShikiHighlighter = createSingleton((opts) => {
|
|
|
56
68
|
lang,
|
|
57
69
|
themes: themesObject,
|
|
58
70
|
defaultColor: false,
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
71
|
+
transformers: [
|
|
72
|
+
...transformers,
|
|
73
|
+
{
|
|
74
|
+
name: "mdc:highlight",
|
|
75
|
+
line(node, line) {
|
|
76
|
+
if (highlights.includes(line))
|
|
77
|
+
addClassToHast(node, "highlight");
|
|
78
|
+
node.properties.line = line;
|
|
64
79
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: "mdc:newline",
|
|
83
|
+
line(node) {
|
|
84
|
+
if (code?.includes("\n")) {
|
|
85
|
+
if (node.children.length === 0 || node.children.length === 1 && node.children[0].type === "element" && node.children[0].children.length === 1 && node.children[0].children[0].type === "text" && node.children[0].children[0].value === "") {
|
|
86
|
+
node.children = [{
|
|
87
|
+
type: "element",
|
|
88
|
+
tagName: "span",
|
|
89
|
+
properties: {
|
|
90
|
+
emptyLinePlaceholder: true
|
|
91
|
+
},
|
|
92
|
+
children: [{ type: "text", value: "\n" }]
|
|
93
|
+
}];
|
|
94
|
+
return;
|
|
95
|
+
}
|
|
96
|
+
const last = node.children.at(-1);
|
|
97
|
+
if (last?.type === "element" && last.tagName === "span") {
|
|
98
|
+
const text = last.children.at(-1);
|
|
99
|
+
if (text?.type === "text")
|
|
100
|
+
text.value += "\n";
|
|
101
|
+
}
|
|
83
102
|
}
|
|
84
103
|
}
|
|
85
104
|
}
|
|
86
|
-
|
|
105
|
+
]
|
|
87
106
|
});
|
|
88
107
|
const preEl = root.children[0];
|
|
89
108
|
const codeEl = preEl.children[0];
|
|
@@ -113,7 +132,7 @@ export const useShikiHighlighter = createSingleton((opts) => {
|
|
|
113
132
|
});
|
|
114
133
|
return {
|
|
115
134
|
tree: codeEl.children,
|
|
116
|
-
className: preEl.properties.class,
|
|
135
|
+
className: Array.isArray(preEl.properties.class) ? preEl.properties.class.join(" ") : preEl.properties.class,
|
|
117
136
|
inlineStyle: preEl.properties.style,
|
|
118
137
|
style: styles.join("")
|
|
119
138
|
};
|
package/dist/types.d.mts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/mdc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Nuxt MDC module",
|
|
5
5
|
"repository": "nuxt-modules/mdc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -34,54 +34,56 @@
|
|
|
34
34
|
"test:watch": "vitest watch"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"@nuxt/kit": "^3.
|
|
37
|
+
"@nuxt/kit": "^3.9.3",
|
|
38
38
|
"@types/hast": "^3.0.3",
|
|
39
39
|
"@types/mdast": "^4.0.3",
|
|
40
|
-
"@vue/compiler-core": "^3.
|
|
40
|
+
"@vue/compiler-core": "^3.4.15",
|
|
41
41
|
"consola": "^3.2.3",
|
|
42
|
-
"defu": "^6.1.
|
|
42
|
+
"defu": "^6.1.4",
|
|
43
43
|
"destr": "^2.0.2",
|
|
44
44
|
"detab": "^3.0.2",
|
|
45
45
|
"github-slugger": "^2.0.0",
|
|
46
46
|
"hast-util-to-string": "^3.0.0",
|
|
47
|
-
"mdast-util-to-hast": "^13.0
|
|
47
|
+
"mdast-util-to-hast": "^13.1.0",
|
|
48
48
|
"micromark-util-sanitize-uri": "^2.0.0",
|
|
49
49
|
"ohash": "^1.1.3",
|
|
50
50
|
"property-information": "^6.4.0",
|
|
51
51
|
"rehype-external-links": "^3.0.0",
|
|
52
|
-
"rehype-raw": "^
|
|
52
|
+
"rehype-raw": "^7.0.0",
|
|
53
53
|
"rehype-slug": "^6.0.0",
|
|
54
54
|
"rehype-sort-attribute-values": "^5.0.0",
|
|
55
55
|
"rehype-sort-attributes": "^5.0.0",
|
|
56
56
|
"remark-emoji": "^4.0.1",
|
|
57
|
-
"remark-gfm": "^
|
|
58
|
-
"remark-mdc": "^
|
|
59
|
-
"remark-parse": "^
|
|
60
|
-
"remark-rehype": "^
|
|
61
|
-
"scule": "^1.
|
|
62
|
-
"shikiji": "^0.9.
|
|
57
|
+
"remark-gfm": "^4.0.0",
|
|
58
|
+
"remark-mdc": "^3.0.1",
|
|
59
|
+
"remark-parse": "^11.0.0",
|
|
60
|
+
"remark-rehype": "^11.1.0",
|
|
61
|
+
"scule": "^1.2.0",
|
|
62
|
+
"shikiji": "^0.9.19",
|
|
63
|
+
"shikiji-transformers": "^0.9.19",
|
|
63
64
|
"ufo": "^1.3.2",
|
|
64
65
|
"unified": "^11.0.4",
|
|
65
66
|
"unist-builder": "^4.0.0",
|
|
66
|
-
"unist-util-visit": "^5.0.0"
|
|
67
|
+
"unist-util-visit": "^5.0.0",
|
|
68
|
+
"unwasm": "^0.3.7"
|
|
67
69
|
},
|
|
68
70
|
"devDependencies": {
|
|
69
71
|
"@nuxt/devtools": "latest",
|
|
70
72
|
"@nuxt/eslint-config": "^0.2.0",
|
|
71
|
-
"@nuxt/module-builder": "^0.5.
|
|
72
|
-
"@nuxt/schema": "^3.
|
|
73
|
-
"@nuxt/test-utils": "^3.
|
|
74
|
-
"@nuxt/ui": "^2.
|
|
73
|
+
"@nuxt/module-builder": "^0.5.5",
|
|
74
|
+
"@nuxt/schema": "^3.9.3",
|
|
75
|
+
"@nuxt/test-utils": "^3.10.0",
|
|
76
|
+
"@nuxt/ui": "^2.12.2",
|
|
75
77
|
"@types/mdurl": "^1.0.5",
|
|
76
|
-
"@types/node": "^20.
|
|
78
|
+
"@types/node": "^20.11.5",
|
|
77
79
|
"changelogen": "^0.5.5",
|
|
78
|
-
"eslint": "^8.
|
|
79
|
-
"nuxt": "^3.
|
|
80
|
+
"eslint": "^8.56.0",
|
|
81
|
+
"nuxt": "^3.9.3",
|
|
80
82
|
"rehype": "^13.0.1",
|
|
81
83
|
"release-it": "^17.0.1",
|
|
82
|
-
"vitest": "^1.
|
|
84
|
+
"vitest": "^1.2.1"
|
|
83
85
|
},
|
|
84
|
-
"packageManager": "pnpm@8.
|
|
86
|
+
"packageManager": "pnpm@8.14.1",
|
|
85
87
|
"release-it": {
|
|
86
88
|
"git": {
|
|
87
89
|
"commitMessage": "chore(release): release v${version}"
|