@nuxtjs/mdc 0.9.0 → 0.9.2
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.d.mts +10 -1
- package/dist/module.d.ts +10 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +22 -11
- package/dist/runtime/components/MDCRenderer.vue +3 -6
- package/dist/runtime/components/MDCRenderer.vue.d.ts +2 -2
- package/dist/runtime/components/prose/ProseImg.vue +3 -3
- package/dist/runtime/highlighter/event-handler.js +1 -1
- package/dist/runtime/highlighter/shiki.d.ts +3 -2
- package/dist/runtime/highlighter/shiki.js +6 -5
- package/dist/runtime/parser/index.js +1 -1
- package/package.json +24 -24
package/dist/module.d.mts
CHANGED
|
@@ -122,6 +122,15 @@ interface ModuleOptions {
|
|
|
122
122
|
* Additional themes to be bundled loaded by Shiki
|
|
123
123
|
*/
|
|
124
124
|
themes?: (BundledTheme | ThemeRegistrationAny)[];
|
|
125
|
+
/**
|
|
126
|
+
* Engine to be used for Shiki
|
|
127
|
+
*
|
|
128
|
+
* Note that the `javascript` engine still in experimental, use with caution.
|
|
129
|
+
*
|
|
130
|
+
* @see https://shiki.style/guide/regex-engines
|
|
131
|
+
* @default 'oniguruma'
|
|
132
|
+
*/
|
|
133
|
+
shikiEngine?: 'oniguruma' | 'javascript';
|
|
125
134
|
/**
|
|
126
135
|
* Preloaded languages that will be available for highlighting code blocks.
|
|
127
136
|
*
|
|
@@ -134,6 +143,7 @@ interface ModuleOptions {
|
|
|
134
143
|
* @default false
|
|
135
144
|
*/
|
|
136
145
|
wrapperStyle?: boolean | string;
|
|
146
|
+
noApiRoute?: boolean;
|
|
137
147
|
} | false;
|
|
138
148
|
headings?: {
|
|
139
149
|
anchorLinks?: {
|
|
@@ -519,7 +529,6 @@ declare module '@nuxt/schema' {
|
|
|
519
529
|
map: Record<string, string>;
|
|
520
530
|
};
|
|
521
531
|
headings: ModuleOptions['headings'];
|
|
522
|
-
useNuxtImage?: boolean;
|
|
523
532
|
};
|
|
524
533
|
}
|
|
525
534
|
interface ConfigSchema {
|
package/dist/module.d.ts
CHANGED
|
@@ -122,6 +122,15 @@ interface ModuleOptions {
|
|
|
122
122
|
* Additional themes to be bundled loaded by Shiki
|
|
123
123
|
*/
|
|
124
124
|
themes?: (BundledTheme | ThemeRegistrationAny)[];
|
|
125
|
+
/**
|
|
126
|
+
* Engine to be used for Shiki
|
|
127
|
+
*
|
|
128
|
+
* Note that the `javascript` engine still in experimental, use with caution.
|
|
129
|
+
*
|
|
130
|
+
* @see https://shiki.style/guide/regex-engines
|
|
131
|
+
* @default 'oniguruma'
|
|
132
|
+
*/
|
|
133
|
+
shikiEngine?: 'oniguruma' | 'javascript';
|
|
125
134
|
/**
|
|
126
135
|
* Preloaded languages that will be available for highlighting code blocks.
|
|
127
136
|
*
|
|
@@ -134,6 +143,7 @@ interface ModuleOptions {
|
|
|
134
143
|
* @default false
|
|
135
144
|
*/
|
|
136
145
|
wrapperStyle?: boolean | string;
|
|
146
|
+
noApiRoute?: boolean;
|
|
137
147
|
} | false;
|
|
138
148
|
headings?: {
|
|
139
149
|
anchorLinks?: {
|
|
@@ -519,7 +529,6 @@ declare module '@nuxt/schema' {
|
|
|
519
529
|
map: Record<string, string>;
|
|
520
530
|
};
|
|
521
531
|
headings: ModuleOptions['headings'];
|
|
522
|
-
useNuxtImage?: boolean;
|
|
523
532
|
};
|
|
524
533
|
}
|
|
525
534
|
interface ConfigSchema {
|
package/dist/module.json
CHANGED
package/dist/module.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fs$1, { existsSync } from 'node:fs';
|
|
2
|
-
import { extendViteConfig, useNitro, defineNuxtModule, createResolver, addServerHandler, addComponent, addImports, addServerImports, addComponentsDir,
|
|
2
|
+
import { extendViteConfig, useNitro, defineNuxtModule, createResolver, addServerHandler, addComponent, addImports, addServerImports, addComponentsDir, addTemplate } from '@nuxt/kit';
|
|
3
3
|
import { defu } from 'defu';
|
|
4
4
|
import { resolve } from 'pathe';
|
|
5
5
|
import fs from 'node:fs/promises';
|
|
@@ -97,8 +97,12 @@ async function mdcHighlighter({
|
|
|
97
97
|
...typeof options?.theme === "string" ? [options?.theme] : Object.values(options?.theme || {}),
|
|
98
98
|
...options?.themes || []
|
|
99
99
|
]));
|
|
100
|
+
const {
|
|
101
|
+
shikiEngine = "oniguruma"
|
|
102
|
+
} = options;
|
|
100
103
|
return [
|
|
101
104
|
"import { getMdcConfigs } from '#mdc-configs'",
|
|
105
|
+
shikiEngine === "javascript" ? "import { createJavaScriptRegexEngine } from 'shiki/engine/javascript'" : "import { createWasmOnigEngine } from 'shiki/engine/oniguruma'",
|
|
102
106
|
code,
|
|
103
107
|
"const bundledLangs = {",
|
|
104
108
|
...Array.from(langsMap.entries()).map(([name, lang]) => typeof lang === "string" ? JSON.stringify(name) + `: () => import('shiki/langs/${lang}.mjs'),` : JSON.stringify(name) + ": " + JSON.stringify(lang) + ","),
|
|
@@ -110,7 +114,8 @@ async function mdcHighlighter({
|
|
|
110
114
|
theme: options.theme,
|
|
111
115
|
wrapperStyle: options.wrapperStyle
|
|
112
116
|
}),
|
|
113
|
-
"const
|
|
117
|
+
shikiEngine === "javascript" ? "const engine = createJavaScriptRegexEngine({ forgiving: true })" : `const engine = createWasmOnigEngine(() => import('shiki/wasm'))`,
|
|
118
|
+
"const highlighter = createShikiHighlighter({ bundledLangs, bundledThemes, options, getMdcConfigs, engine })",
|
|
114
119
|
"export default highlighter"
|
|
115
120
|
].join("\n");
|
|
116
121
|
}
|
|
@@ -248,10 +253,12 @@ const module = defineNuxtModule({
|
|
|
248
253
|
});
|
|
249
254
|
if (options.highlight) {
|
|
250
255
|
addWasmSupport(nuxt);
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
256
|
+
if (options.highlight?.noApiRoute !== true) {
|
|
257
|
+
addServerHandler({
|
|
258
|
+
route: "/api/_mdc/highlight",
|
|
259
|
+
handler: resolver.resolve("./runtime/highlighter/event-handler")
|
|
260
|
+
});
|
|
261
|
+
}
|
|
255
262
|
options.rehypePlugins ||= {};
|
|
256
263
|
options.rehypePlugins.highlight ||= {};
|
|
257
264
|
options.rehypePlugins.highlight.src ||= await resolver.resolvePath("./runtime/highlighter/rehype-nuxt");
|
|
@@ -322,11 +329,14 @@ const module = defineNuxtModule({
|
|
|
322
329
|
global: true
|
|
323
330
|
});
|
|
324
331
|
}
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
})
|
|
329
|
-
|
|
332
|
+
addTemplate({
|
|
333
|
+
filename: "mdc-image-component.mjs",
|
|
334
|
+
write: true,
|
|
335
|
+
getContents: ({ app }) => {
|
|
336
|
+
const image = app.components.find((c) => c.pascalName === "NuxtImg" && !c.filePath.includes("nuxt/dist/app"));
|
|
337
|
+
return image ? `export { default } from "${image.filePath}"` : 'export default "img"';
|
|
338
|
+
}
|
|
339
|
+
});
|
|
330
340
|
extendViteConfig((config) => {
|
|
331
341
|
const include = [
|
|
332
342
|
"remark-gfm",
|
|
@@ -393,6 +403,7 @@ function resolveOptions(options) {
|
|
|
393
403
|
default: "github-light",
|
|
394
404
|
dark: "github-dark"
|
|
395
405
|
};
|
|
406
|
+
options.highlight.shikiEngine ||= "oniguruma";
|
|
396
407
|
options.highlight.langs ||= DefaultHighlightLangs;
|
|
397
408
|
if (options.highlight.preload) {
|
|
398
409
|
options.highlight.langs.push(...options.highlight.preload || []);
|
|
@@ -29,7 +29,7 @@ export default defineComponent({
|
|
|
29
29
|
default: () => ({})
|
|
30
30
|
},
|
|
31
31
|
/**
|
|
32
|
-
*
|
|
32
|
+
* Class(es) to bind to the component
|
|
33
33
|
*/
|
|
34
34
|
class: {
|
|
35
35
|
type: [String, Object],
|
|
@@ -234,11 +234,8 @@ function propsToDataRxBind(key, value, data, documentMeta) {
|
|
|
234
234
|
return data;
|
|
235
235
|
}
|
|
236
236
|
const resolveVueComponent = (component) => {
|
|
237
|
-
if (
|
|
238
|
-
|
|
239
|
-
if (typeof componentFn === "object") {
|
|
240
|
-
return componentFn;
|
|
241
|
-
}
|
|
237
|
+
if (typeof component === "string") {
|
|
238
|
+
return htmlTags.includes(component) ? component : resolveComponent(pascalCase(component), false);
|
|
242
239
|
}
|
|
243
240
|
return component;
|
|
244
241
|
};
|
|
@@ -16,7 +16,7 @@ declare const _default: DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
16
16
|
default: () => {};
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* Class(es) to bind to the component
|
|
20
20
|
*/
|
|
21
21
|
class: {
|
|
22
22
|
type: (ObjectConstructor | StringConstructor)[];
|
|
@@ -71,7 +71,7 @@ declare const _default: DefineComponent<import("vue").ExtractPropTypes<{
|
|
|
71
71
|
default: () => {};
|
|
72
72
|
};
|
|
73
73
|
/**
|
|
74
|
-
*
|
|
74
|
+
* Class(es) to bind to the component
|
|
75
75
|
*/
|
|
76
76
|
class: {
|
|
77
77
|
type: (ObjectConstructor | StringConstructor)[];
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
<template>
|
|
2
2
|
<component
|
|
3
|
-
:is="
|
|
3
|
+
:is="ImageComponent"
|
|
4
4
|
:src="refinedSrc"
|
|
5
5
|
:alt="props.alt"
|
|
6
6
|
:width="props.width"
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
|
|
11
11
|
<script setup lang="ts">
|
|
12
12
|
import { withTrailingSlash, withLeadingSlash, joinURL } from 'ufo'
|
|
13
|
-
import { useRuntimeConfig, computed
|
|
13
|
+
import { useRuntimeConfig, computed } from '#imports'
|
|
14
14
|
|
|
15
|
-
|
|
15
|
+
import ImageComponent from '#build/mdc-image-component.mjs'
|
|
16
16
|
|
|
17
17
|
const props = defineProps({
|
|
18
18
|
src: {
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { eventHandler, getQuery } from "h3";
|
|
2
|
-
import highlighter from "#mdc-highlighter";
|
|
3
2
|
export default eventHandler(async (event) => {
|
|
4
3
|
const { code, lang, theme: themeString, options: optionsStr } = getQuery(event);
|
|
5
4
|
const theme = JSON.parse(themeString);
|
|
6
5
|
const options = optionsStr ? JSON.parse(optionsStr) : {};
|
|
6
|
+
const highlighter = await import("#mdc-highlighter").then((m) => m.default);
|
|
7
7
|
return await highlighter(code, lang, theme, options);
|
|
8
8
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { LanguageInput, ThemeInput } from 'shiki';
|
|
1
|
+
import type { LanguageInput, ThemeInput, RegexEngine } from 'shiki';
|
|
2
2
|
import type { MdcConfig, Highlighter } from '@nuxtjs/mdc';
|
|
3
3
|
export interface CreateShikiHighlighterOptions {
|
|
4
4
|
themes?: ThemeInput[];
|
|
@@ -9,5 +9,6 @@ export interface CreateShikiHighlighterOptions {
|
|
|
9
9
|
wrapperStyle?: string;
|
|
10
10
|
};
|
|
11
11
|
getMdcConfigs?: () => Promise<MdcConfig[]>;
|
|
12
|
+
engine?: RegexEngine | Promise<RegexEngine>;
|
|
12
13
|
}
|
|
13
|
-
export declare function createShikiHighlighter({ langs, themes, bundledLangs, bundledThemes, getMdcConfigs, options: shikiOptions }?: CreateShikiHighlighterOptions): Highlighter;
|
|
14
|
+
export declare function createShikiHighlighter({ langs, themes, bundledLangs, bundledThemes, getMdcConfigs, options: shikiOptions, engine }?: CreateShikiHighlighterOptions): Highlighter;
|
|
@@ -4,7 +4,8 @@ export function createShikiHighlighter({
|
|
|
4
4
|
bundledLangs = {},
|
|
5
5
|
bundledThemes = {},
|
|
6
6
|
getMdcConfigs,
|
|
7
|
-
options: shikiOptions
|
|
7
|
+
options: shikiOptions,
|
|
8
|
+
engine
|
|
8
9
|
} = {}) {
|
|
9
10
|
let shiki;
|
|
10
11
|
let configs;
|
|
@@ -14,7 +15,7 @@ export function createShikiHighlighter({
|
|
|
14
15
|
const shiki2 = await createHighlighterCore({
|
|
15
16
|
langs,
|
|
16
17
|
themes,
|
|
17
|
-
|
|
18
|
+
engine
|
|
18
19
|
});
|
|
19
20
|
for await (const config of await getConfigs()) {
|
|
20
21
|
await config.shiki?.setup?.(shiki2);
|
|
@@ -65,14 +66,14 @@ export function createShikiHighlighter({
|
|
|
65
66
|
lang = "vue";
|
|
66
67
|
codeToHastOptions.grammarContextCode = "<template>";
|
|
67
68
|
}
|
|
68
|
-
const themesObject = typeof theme === "string" ? { default: theme } : theme || {};
|
|
69
|
+
const themesObject = { ...typeof theme === "string" ? { default: theme } : theme || {} };
|
|
69
70
|
const loadedThemes = shiki2.getLoadedThemes();
|
|
70
71
|
const loadedLanguages = shiki2.getLoadedLanguages();
|
|
71
72
|
if (typeof lang === "string" && !loadedLanguages.includes(lang) && !isSpecialLang(lang)) {
|
|
72
73
|
if (bundledLangs[lang]) {
|
|
73
74
|
await shiki2.loadLanguage(bundledLangs[lang]);
|
|
74
75
|
} else {
|
|
75
|
-
if (
|
|
76
|
+
if (process.dev) {
|
|
76
77
|
console.warn(`[@nuxtjs/mdc] Language "${lang}" is not loaded to the Shiki highlighter, fallback to plain text. Add the language to "mdc.highlight.langs" to fix this.`);
|
|
77
78
|
}
|
|
78
79
|
lang = "text";
|
|
@@ -83,7 +84,7 @@ export function createShikiHighlighter({
|
|
|
83
84
|
if (bundledThemes[theme2]) {
|
|
84
85
|
await shiki2.loadTheme(bundledThemes[theme2]);
|
|
85
86
|
} else {
|
|
86
|
-
if (
|
|
87
|
+
if (process.dev) {
|
|
87
88
|
console.warn(`[@nuxtjs/mdc] Theme "${theme2}" is not loaded to the Shiki highlighter. Add the theme to "mdc.highlight.themes" to fix this.`);
|
|
88
89
|
}
|
|
89
90
|
themesObject[color] = "none";
|
|
@@ -28,7 +28,7 @@ export const createMarkdownParser = async (inlineOptions = {}) => {
|
|
|
28
28
|
...inlineOptions.configs || []
|
|
29
29
|
];
|
|
30
30
|
if (inlineOptions.highlight != null && inlineOptions.highlight != false && inlineOptions.highlight.highlighter !== void 0 && typeof inlineOptions.highlight.highlighter !== "function") {
|
|
31
|
-
if (
|
|
31
|
+
if (process.dev)
|
|
32
32
|
console.warn("[@nuxtjs/mdc] `highlighter` passed to `parseMarkdown` is should be a function, but got " + JSON.stringify(inlineOptions.highlight.highlighter) + ", ignored.");
|
|
33
33
|
inlineOptions = {
|
|
34
34
|
...inlineOptions,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/mdc",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.2",
|
|
4
4
|
"description": "Nuxt MDC module",
|
|
5
5
|
"repository": "nuxt-modules/mdc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -71,36 +71,36 @@
|
|
|
71
71
|
"test:watch": "vitest watch"
|
|
72
72
|
},
|
|
73
73
|
"dependencies": {
|
|
74
|
-
"@nuxt/kit": "^3.13.
|
|
75
|
-
"@shikijs/transformers": "^1.
|
|
74
|
+
"@nuxt/kit": "^3.13.2",
|
|
75
|
+
"@shikijs/transformers": "^1.22.0",
|
|
76
76
|
"@types/hast": "^3.0.4",
|
|
77
77
|
"@types/mdast": "^4.0.4",
|
|
78
|
-
"@vue/compiler-core": "^3.5.
|
|
78
|
+
"@vue/compiler-core": "^3.5.12",
|
|
79
79
|
"consola": "^3.2.3",
|
|
80
80
|
"debug": "^4.3.7",
|
|
81
81
|
"defu": "^6.1.4",
|
|
82
82
|
"destr": "^2.0.3",
|
|
83
83
|
"detab": "^3.0.2",
|
|
84
84
|
"github-slugger": "^2.0.0",
|
|
85
|
-
"hast-util-to-string": "^3.0.
|
|
85
|
+
"hast-util-to-string": "^3.0.1",
|
|
86
86
|
"mdast-util-to-hast": "^13.2.0",
|
|
87
87
|
"micromark-util-sanitize-uri": "^2.0.0",
|
|
88
|
-
"ohash": "^1.1.
|
|
89
|
-
"parse5": "^7.
|
|
88
|
+
"ohash": "^1.1.4",
|
|
89
|
+
"parse5": "^7.2.0",
|
|
90
90
|
"pathe": "^1.1.2",
|
|
91
91
|
"property-information": "^6.5.0",
|
|
92
92
|
"rehype-external-links": "^3.0.0",
|
|
93
93
|
"rehype-raw": "^7.0.0",
|
|
94
94
|
"rehype-slug": "^6.0.0",
|
|
95
|
-
"rehype-sort-attribute-values": "^5.0.
|
|
96
|
-
"rehype-sort-attributes": "^5.0.
|
|
95
|
+
"rehype-sort-attribute-values": "^5.0.1",
|
|
96
|
+
"rehype-sort-attributes": "^5.0.1",
|
|
97
97
|
"remark-emoji": "^5.0.1",
|
|
98
98
|
"remark-gfm": "^4.0.0",
|
|
99
99
|
"remark-mdc": "^3.2.1",
|
|
100
100
|
"remark-parse": "^11.0.0",
|
|
101
|
-
"remark-rehype": "^11.1.
|
|
101
|
+
"remark-rehype": "^11.1.1",
|
|
102
102
|
"scule": "^1.3.0",
|
|
103
|
-
"shiki": "^1.
|
|
103
|
+
"shiki": "^1.22.0",
|
|
104
104
|
"ufo": "^1.5.4",
|
|
105
105
|
"unified": "^11.0.5",
|
|
106
106
|
"unist-builder": "^4.0.0",
|
|
@@ -109,23 +109,23 @@
|
|
|
109
109
|
},
|
|
110
110
|
"devDependencies": {
|
|
111
111
|
"@nuxt/devtools": "latest",
|
|
112
|
-
"@nuxt/eslint-config": "^0.
|
|
112
|
+
"@nuxt/eslint-config": "^0.6.0",
|
|
113
113
|
"@nuxt/module-builder": "^0.8.4",
|
|
114
|
-
"@nuxt/schema": "^3.13.
|
|
115
|
-
"@nuxt/test-utils": "^3.14.
|
|
116
|
-
"@nuxt/ui": "^2.18.
|
|
114
|
+
"@nuxt/schema": "^3.13.2",
|
|
115
|
+
"@nuxt/test-utils": "^3.14.3",
|
|
116
|
+
"@nuxt/ui": "^2.18.7",
|
|
117
117
|
"@nuxtjs/mdc": "link:.",
|
|
118
|
-
"@types/node": "^22.5
|
|
119
|
-
"changelogen": "^0.5.
|
|
120
|
-
"eslint": "^9.
|
|
121
|
-
"nuxt": "^3.13.
|
|
122
|
-
"rehype": "^13.0.
|
|
123
|
-
"release-it": "^17.
|
|
124
|
-
"typescript": "^5.6.
|
|
125
|
-
"vitest": "^2.
|
|
118
|
+
"@types/node": "^22.7.5",
|
|
119
|
+
"changelogen": "^0.5.7",
|
|
120
|
+
"eslint": "^9.12.0",
|
|
121
|
+
"nuxt": "^3.13.2",
|
|
122
|
+
"rehype": "^13.0.2",
|
|
123
|
+
"release-it": "^17.9.0",
|
|
124
|
+
"typescript": "^5.6.3",
|
|
125
|
+
"vitest": "^2.1.3",
|
|
126
126
|
"vue-tsc": "^2.1.6"
|
|
127
127
|
},
|
|
128
|
-
"packageManager": "pnpm@9.
|
|
128
|
+
"packageManager": "pnpm@9.12.1",
|
|
129
129
|
"release-it": {
|
|
130
130
|
"git": {
|
|
131
131
|
"commitMessage": "chore(release): release v${version}"
|