@nuxtjs/mdc 0.3.2 → 0.5.0
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/config.cjs +1 -0
- package/dist/config.d.mts +49 -0
- package/dist/config.d.ts +49 -0
- package/dist/config.mjs +5 -0
- package/dist/module.d.mts +39 -14
- package/dist/module.d.ts +39 -14
- package/dist/module.json +1 -1
- package/dist/module.mjs +261 -79
- package/dist/runtime/components/MDCRenderer.vue +2 -2
- package/dist/runtime/{shiki → highlighter}/event-handler.d.ts +1 -1
- package/dist/runtime/highlighter/event-handler.mjs +8 -0
- package/dist/runtime/highlighter/rehype.d.ts +8 -0
- package/dist/runtime/{shiki/index.mjs → highlighter/rehype.mjs} +12 -13
- package/dist/runtime/highlighter/shiki.d.ts +14 -0
- package/dist/runtime/highlighter/shiki.mjs +159 -0
- package/dist/runtime/highlighter/types.d.ts +14 -0
- package/dist/runtime/index.d.ts +0 -1
- package/dist/runtime/index.mjs +0 -1
- package/dist/runtime/parser/compiler.mjs +2 -1
- package/dist/runtime/parser/index.d.ts +1 -1
- package/dist/runtime/parser/index.mjs +38 -4
- package/dist/runtime/types/config.d.ts +45 -0
- package/dist/runtime/types/config.mjs +0 -0
- package/dist/runtime/types/parser.d.ts +7 -5
- package/dist/runtime/utils/node.d.ts +1 -1
- package/dist/shared/mdc.a6f76af4.d.mts +9 -0
- package/dist/shared/mdc.a6f76af4.d.ts +9 -0
- package/dist/types.d.mts +1 -1
- package/dist/types.d.ts +1 -1
- package/package.json +34 -15
- package/dist/runtime/shiki/event-handler.mjs +0 -17
- package/dist/runtime/shiki/highlighter.d.ts +0 -5
- package/dist/runtime/shiki/highlighter.mjs +0 -161
- package/dist/runtime/shiki/index.d.ts +0 -8
- package/dist/runtime/shiki/types.d.ts +0 -13
- /package/dist/runtime/{shiki → highlighter}/types.mjs +0 -0
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<
|
|
1
|
+
declare const _default: import("h3").EventHandler<import("h3").EventHandlerRequest, Promise<any>>;
|
|
2
2
|
export default _default;
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { eventHandler, getQuery } from "h3";
|
|
2
|
+
import highlighter from "#mdc-highlighter";
|
|
3
|
+
export default eventHandler(async (event) => {
|
|
4
|
+
const { code, lang, theme: themeString, options: optionsStr } = getQuery(event);
|
|
5
|
+
const theme = JSON.parse(themeString);
|
|
6
|
+
const options = optionsStr ? JSON.parse(optionsStr) : {};
|
|
7
|
+
return await highlighter(code, lang, theme, options);
|
|
8
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Root } from 'hast';
|
|
2
|
+
import type { Highlighter, MdcThemeOptions } from './types';
|
|
3
|
+
export interface RehypeHighlightOption {
|
|
4
|
+
theme?: MdcThemeOptions;
|
|
5
|
+
highlighter?: Highlighter;
|
|
6
|
+
}
|
|
7
|
+
export default rehypeHighlight;
|
|
8
|
+
export declare function rehypeHighlight(opts?: RehypeHighlightOption): (tree: Root) => Promise<void>;
|
|
@@ -1,15 +1,10 @@
|
|
|
1
1
|
import { visit } from "unist-util-visit";
|
|
2
2
|
import { toString } from "hast-util-to-string";
|
|
3
3
|
const defaults = {
|
|
4
|
-
theme: {
|
|
5
|
-
|
|
6
|
-
dark: "github-dark"
|
|
7
|
-
},
|
|
8
|
-
async highlighter(code, lang, theme, highlights) {
|
|
4
|
+
theme: {},
|
|
5
|
+
async highlighter(code, lang, theme, options) {
|
|
9
6
|
if (process.browser && window.sessionStorage.getItem("mdc-shiki-highlighter") === "browser") {
|
|
10
|
-
return import("
|
|
11
|
-
return useShikiHighlighter().getHighlightedAST(code, lang, theme, { highlights });
|
|
12
|
-
});
|
|
7
|
+
return import("#mdc-highlighter").then((h) => h.default(code, lang, theme, options));
|
|
13
8
|
}
|
|
14
9
|
try {
|
|
15
10
|
return await $fetch("/api/_mdc/highlight", {
|
|
@@ -17,20 +12,20 @@ const defaults = {
|
|
|
17
12
|
code,
|
|
18
13
|
lang,
|
|
19
14
|
theme: JSON.stringify(theme),
|
|
20
|
-
|
|
15
|
+
options: JSON.stringify(options)
|
|
21
16
|
}
|
|
22
17
|
});
|
|
23
18
|
} catch (e) {
|
|
24
19
|
if (process.browser && e?.response?.status === 404) {
|
|
25
20
|
window.sessionStorage.setItem("mdc-shiki-highlighter", "browser");
|
|
26
|
-
return this.highlighter?.(code, lang, theme,
|
|
21
|
+
return this.highlighter?.(code, lang, theme, options);
|
|
27
22
|
}
|
|
28
23
|
}
|
|
29
24
|
return Promise.resolve({ tree: [{ type: "text", value: code }], className: "", style: "" });
|
|
30
25
|
}
|
|
31
26
|
};
|
|
32
|
-
export default
|
|
33
|
-
export function
|
|
27
|
+
export default rehypeHighlight;
|
|
28
|
+
export function rehypeHighlight(opts = {}) {
|
|
34
29
|
const options = { ...defaults, ...opts };
|
|
35
30
|
return async (tree) => {
|
|
36
31
|
const tasks = [];
|
|
@@ -40,11 +35,15 @@ export function rehypeShiki(opts = {}) {
|
|
|
40
35
|
(node) => ["pre", "code"].includes(node.tagName) && !!(node.properties?.language || node.properties?.highlights),
|
|
41
36
|
(node) => {
|
|
42
37
|
const _node = node;
|
|
38
|
+
const highlights = typeof _node.properties.highlights === "string" ? _node.properties.highlights.split(/[,\s]+/).map(Number) : Array.isArray(_node.properties.highlights) ? _node.properties.highlights.map(Number) : [];
|
|
43
39
|
const task = options.highlighter(
|
|
44
40
|
toString(node),
|
|
45
41
|
_node.properties.language,
|
|
46
42
|
options.theme,
|
|
47
|
-
|
|
43
|
+
{
|
|
44
|
+
highlights: highlights.filter(Boolean),
|
|
45
|
+
meta: _node.properties.meta
|
|
46
|
+
}
|
|
48
47
|
).then(({ tree: tree2, className, style, inlineStyle }) => {
|
|
49
48
|
_node.properties.className = ((_node.properties.className || "") + " " + className).trim();
|
|
50
49
|
_node.properties.style = ((_node.properties.style || "") + " " + inlineStyle).trim();
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LanguageInput, ThemeInput } from 'shiki';
|
|
2
|
+
import type { Highlighter } from './types';
|
|
3
|
+
import type { MdcConfig } from '../types/config';
|
|
4
|
+
export interface CreateShikiHighlighterOptions {
|
|
5
|
+
themes?: ThemeInput[];
|
|
6
|
+
langs?: LanguageInput[];
|
|
7
|
+
bundledThemes?: Record<string, ThemeInput>;
|
|
8
|
+
bundledLangs?: Record<string, LanguageInput>;
|
|
9
|
+
options?: {
|
|
10
|
+
wrapperStyle?: string;
|
|
11
|
+
};
|
|
12
|
+
getMdcConfigs?: () => Promise<MdcConfig[]>;
|
|
13
|
+
}
|
|
14
|
+
export declare function createShikiHighlighter({ langs, themes, bundledLangs, bundledThemes, getMdcConfigs, options: shikiOptions }?: CreateShikiHighlighterOptions): Highlighter;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
import { getHighlighterCore, addClassToHast, isSpecialLang, isSpecialTheme } from "shiki/core";
|
|
2
|
+
import {
|
|
3
|
+
transformerNotationDiff,
|
|
4
|
+
transformerNotationErrorLevel,
|
|
5
|
+
transformerNotationFocus,
|
|
6
|
+
transformerNotationHighlight
|
|
7
|
+
} from "@shikijs/transformers";
|
|
8
|
+
export function createShikiHighlighter({
|
|
9
|
+
langs = [],
|
|
10
|
+
themes = [],
|
|
11
|
+
bundledLangs = {},
|
|
12
|
+
bundledThemes = {},
|
|
13
|
+
getMdcConfigs,
|
|
14
|
+
options: shikiOptions
|
|
15
|
+
} = {}) {
|
|
16
|
+
let shiki;
|
|
17
|
+
let configs;
|
|
18
|
+
async function _getShiki() {
|
|
19
|
+
const shiki2 = await getHighlighterCore({
|
|
20
|
+
langs,
|
|
21
|
+
themes,
|
|
22
|
+
loadWasm: () => import("shiki/wasm")
|
|
23
|
+
});
|
|
24
|
+
for await (const config of await getConfigs()) {
|
|
25
|
+
await config.shiki?.setup?.(shiki2);
|
|
26
|
+
}
|
|
27
|
+
return shiki2;
|
|
28
|
+
}
|
|
29
|
+
async function getShiki() {
|
|
30
|
+
if (!shiki) {
|
|
31
|
+
shiki = _getShiki();
|
|
32
|
+
}
|
|
33
|
+
return shiki;
|
|
34
|
+
}
|
|
35
|
+
async function getConfigs() {
|
|
36
|
+
if (!configs) {
|
|
37
|
+
configs = Promise.resolve(getMdcConfigs?.() || []);
|
|
38
|
+
}
|
|
39
|
+
return configs;
|
|
40
|
+
}
|
|
41
|
+
const baseTransformers = [
|
|
42
|
+
transformerNotationDiff(),
|
|
43
|
+
transformerNotationFocus(),
|
|
44
|
+
transformerNotationHighlight(),
|
|
45
|
+
transformerNotationErrorLevel()
|
|
46
|
+
];
|
|
47
|
+
const highlighter = async (code, lang, theme, options = {}) => {
|
|
48
|
+
const shiki2 = await getShiki();
|
|
49
|
+
const themesObject = typeof theme === "string" ? { default: theme } : theme || {};
|
|
50
|
+
const loadedThemes = shiki2.getLoadedThemes();
|
|
51
|
+
const loadedLanguages = shiki2.getLoadedLanguages();
|
|
52
|
+
if (typeof lang === "string" && !loadedLanguages.includes(lang) && !isSpecialLang(lang)) {
|
|
53
|
+
if (bundledLangs[lang]) {
|
|
54
|
+
await shiki2.loadLanguage(bundledLangs[lang]);
|
|
55
|
+
} else {
|
|
56
|
+
if (process.dev) {
|
|
57
|
+
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.`);
|
|
58
|
+
}
|
|
59
|
+
lang = "text";
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
for (const [color, theme2] of Object.entries(themesObject)) {
|
|
63
|
+
if (typeof theme2 === "string" && !loadedThemes.includes(theme2) && !isSpecialTheme(theme2)) {
|
|
64
|
+
if (bundledThemes[theme2]) {
|
|
65
|
+
await shiki2.loadTheme(bundledThemes[theme2]);
|
|
66
|
+
} else {
|
|
67
|
+
if (process.dev) {
|
|
68
|
+
console.warn(`[@nuxtjs/mdc] Theme "${theme2}" is not loaded to the Shiki highlighter. Add the theme to "mdc.highlight.themes" to fix this.`);
|
|
69
|
+
}
|
|
70
|
+
themesObject[color] = "none";
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
const transformers = [
|
|
75
|
+
...baseTransformers
|
|
76
|
+
];
|
|
77
|
+
for (const config of await getConfigs()) {
|
|
78
|
+
const newTransformers = typeof config.shiki?.transformers === "function" ? await config.shiki?.transformers(code, lang, theme, options) : config.shiki?.transformers || [];
|
|
79
|
+
transformers.push(...newTransformers);
|
|
80
|
+
}
|
|
81
|
+
const root = shiki2.codeToHast(code.trimEnd(), {
|
|
82
|
+
lang,
|
|
83
|
+
themes: themesObject,
|
|
84
|
+
defaultColor: false,
|
|
85
|
+
meta: {
|
|
86
|
+
__raw: options.meta
|
|
87
|
+
},
|
|
88
|
+
transformers: [
|
|
89
|
+
...transformers,
|
|
90
|
+
{
|
|
91
|
+
name: "mdc:highlight",
|
|
92
|
+
line(node, line) {
|
|
93
|
+
if (options.highlights?.includes(line))
|
|
94
|
+
addClassToHast(node, "highlight");
|
|
95
|
+
node.properties.line = line;
|
|
96
|
+
}
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
name: "mdc:newline",
|
|
100
|
+
line(node) {
|
|
101
|
+
if (code?.includes("\n")) {
|
|
102
|
+
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 === "") {
|
|
103
|
+
node.children = [{
|
|
104
|
+
type: "element",
|
|
105
|
+
tagName: "span",
|
|
106
|
+
properties: {
|
|
107
|
+
emptyLinePlaceholder: true
|
|
108
|
+
},
|
|
109
|
+
children: [{ type: "text", value: "\n" }]
|
|
110
|
+
}];
|
|
111
|
+
return;
|
|
112
|
+
}
|
|
113
|
+
const last = node.children.at(-1);
|
|
114
|
+
if (last?.type === "element" && last.tagName === "span") {
|
|
115
|
+
const text = last.children.at(-1);
|
|
116
|
+
if (text?.type === "text")
|
|
117
|
+
text.value += "\n";
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
});
|
|
124
|
+
const preEl = root.children[0];
|
|
125
|
+
const codeEl = preEl.children[0];
|
|
126
|
+
const wrapperStyle = shikiOptions?.wrapperStyle;
|
|
127
|
+
preEl.properties.style = wrapperStyle ? typeof wrapperStyle === "string" ? wrapperStyle : preEl.properties.style : "";
|
|
128
|
+
const styles = [];
|
|
129
|
+
Object.keys(themesObject).forEach((color) => {
|
|
130
|
+
const colorScheme = color !== "default" ? `.${color}` : "";
|
|
131
|
+
styles.push(
|
|
132
|
+
wrapperStyle ? `${colorScheme} .shiki,` : "",
|
|
133
|
+
`html .${color} .shiki span {`,
|
|
134
|
+
`color: var(--shiki-${color});`,
|
|
135
|
+
`background: var(--shiki-${color}-bg);`,
|
|
136
|
+
`font-style: var(--shiki-${color}-font-style);`,
|
|
137
|
+
`font-weight: var(--shiki-${color}-font-weight);`,
|
|
138
|
+
`text-decoration: var(--shiki-${color}-text-decoration);`,
|
|
139
|
+
"}"
|
|
140
|
+
);
|
|
141
|
+
styles.push(
|
|
142
|
+
`html${colorScheme} .shiki span {`,
|
|
143
|
+
`color: var(--shiki-${color});`,
|
|
144
|
+
`background: var(--shiki-${color}-bg);`,
|
|
145
|
+
`font-style: var(--shiki-${color}-font-style);`,
|
|
146
|
+
`font-weight: var(--shiki-${color}-font-weight);`,
|
|
147
|
+
`text-decoration: var(--shiki-${color}-text-decoration);`,
|
|
148
|
+
"}"
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
return {
|
|
152
|
+
tree: codeEl.children,
|
|
153
|
+
className: Array.isArray(preEl.properties.class) ? preEl.properties.class.join(" ") : preEl.properties.class,
|
|
154
|
+
inlineStyle: preEl.properties.style,
|
|
155
|
+
style: styles.join("")
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
return highlighter;
|
|
159
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { ElementContent } from 'hast';
|
|
2
|
+
import type { BuiltinTheme } from 'shiki';
|
|
3
|
+
export type MdcThemeOptions = BuiltinTheme | string | Record<string, BuiltinTheme | string>;
|
|
4
|
+
export interface HighlighterOptions {
|
|
5
|
+
highlights?: number[];
|
|
6
|
+
meta?: string;
|
|
7
|
+
}
|
|
8
|
+
export interface HighlightResult {
|
|
9
|
+
tree: ElementContent[];
|
|
10
|
+
className?: string;
|
|
11
|
+
style?: string;
|
|
12
|
+
inlineStyle?: string;
|
|
13
|
+
}
|
|
14
|
+
export type Highlighter = (code: string, lang: string, theme: MdcThemeOptions, options: Partial<HighlighterOptions>) => Promise<HighlightResult>;
|
package/dist/runtime/index.d.ts
CHANGED
package/dist/runtime/index.mjs
CHANGED
|
@@ -39,11 +39,12 @@ export function compileHast() {
|
|
|
39
39
|
if (node.tagName === "component-slot") {
|
|
40
40
|
node.tagName = "template";
|
|
41
41
|
}
|
|
42
|
+
const children = (node.tagName === "template" && node.content?.children.length ? node.content.children : node.children).map((child) => compileToJSON(child, node)).filter(Boolean);
|
|
42
43
|
return {
|
|
43
44
|
type: "element",
|
|
44
45
|
tag: node.tagName,
|
|
45
46
|
props: validateProps(node.tagName, node.properties),
|
|
46
|
-
children
|
|
47
|
+
children
|
|
47
48
|
};
|
|
48
49
|
}
|
|
49
50
|
if (node.type === "text") {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { MDCData, MDCParseOptions, MDCRoot, Toc } from '../types';
|
|
2
|
-
export declare const parseMarkdown: (md: string,
|
|
2
|
+
export declare const parseMarkdown: (md: string, inlineOptions?: MDCParseOptions) => Promise<{
|
|
3
3
|
data: MDCData;
|
|
4
4
|
body: MDCRoot;
|
|
5
5
|
excerpt: MDCRoot | undefined;
|
|
@@ -9,14 +9,36 @@ import { defaults } from "./options.mjs";
|
|
|
9
9
|
import { generateToc } from "./toc.mjs";
|
|
10
10
|
import { nodeTextContent } from "../utils/node.mjs";
|
|
11
11
|
let moduleOptions;
|
|
12
|
-
|
|
12
|
+
let generatedMdcConfigs;
|
|
13
|
+
export const parseMarkdown = async (md, inlineOptions = {}) => {
|
|
13
14
|
if (!moduleOptions) {
|
|
14
15
|
moduleOptions = await import(
|
|
15
16
|
"#mdc-imports"
|
|
16
17
|
/* @vite-ignore */
|
|
17
18
|
).catch(() => ({}));
|
|
18
19
|
}
|
|
19
|
-
|
|
20
|
+
if (!generatedMdcConfigs) {
|
|
21
|
+
generatedMdcConfigs = await import(
|
|
22
|
+
"#mdc-configs"
|
|
23
|
+
/* @vite-ignore */
|
|
24
|
+
).then((r) => r.getMdcConfigs()).catch(() => []);
|
|
25
|
+
}
|
|
26
|
+
const mdcConfigs = [
|
|
27
|
+
...generatedMdcConfigs || [],
|
|
28
|
+
...inlineOptions.configs || []
|
|
29
|
+
];
|
|
30
|
+
if (inlineOptions.highlight != null && inlineOptions.highlight != false && inlineOptions.highlight.highlighter !== void 0 && typeof inlineOptions.highlight.highlighter !== "function") {
|
|
31
|
+
if (import.meta.dev)
|
|
32
|
+
console.warn("[@nuxtjs/mdc] `highlighter` passed to `parseMarkdown` is should be a function, but got " + JSON.stringify(inlineOptions.highlight.highlighter) + ", ignored.");
|
|
33
|
+
inlineOptions = {
|
|
34
|
+
...inlineOptions,
|
|
35
|
+
highlight: {
|
|
36
|
+
...inlineOptions.highlight
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
delete inlineOptions.highlight.highlighter;
|
|
40
|
+
}
|
|
41
|
+
const options = defu(inlineOptions, {
|
|
20
42
|
remark: { plugins: moduleOptions?.remarkPlugins },
|
|
21
43
|
rehype: { plugins: moduleOptions?.rehypePlugins },
|
|
22
44
|
highlight: moduleOptions?.highlight
|
|
@@ -24,13 +46,25 @@ export const parseMarkdown = async (md, opts = {}) => {
|
|
|
24
46
|
if (options.rehype?.plugins?.highlight) {
|
|
25
47
|
options.rehype.plugins.highlight.options = options.highlight || {};
|
|
26
48
|
}
|
|
27
|
-
|
|
28
|
-
const
|
|
49
|
+
let processor = unified();
|
|
50
|
+
for (const config of mdcConfigs) {
|
|
51
|
+
processor = await config.unified?.pre?.(processor) || processor;
|
|
52
|
+
}
|
|
29
53
|
processor.use(remarkParse);
|
|
54
|
+
for (const config of mdcConfigs) {
|
|
55
|
+
processor = await config.unified?.remark?.(processor) || processor;
|
|
56
|
+
}
|
|
30
57
|
await useProcessorPlugins(processor, options.remark?.plugins);
|
|
31
58
|
processor.use(remark2rehype, options.rehype?.options);
|
|
59
|
+
for (const config of mdcConfigs) {
|
|
60
|
+
processor = await config.unified?.rehype?.(processor) || processor;
|
|
61
|
+
}
|
|
32
62
|
await useProcessorPlugins(processor, options.rehype?.plugins);
|
|
33
63
|
processor.use(compileHast);
|
|
64
|
+
for (const config of mdcConfigs) {
|
|
65
|
+
processor = await config.unified?.post?.(processor) || processor;
|
|
66
|
+
}
|
|
67
|
+
const { content, data: frontmatter } = await parseFrontMatter(md);
|
|
34
68
|
const processedFile = await processor.process({ value: content, data: frontmatter });
|
|
35
69
|
const result = processedFile.result;
|
|
36
70
|
const data = Object.assign(
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import type { Highlighter, HighlighterCore } from 'shiki';
|
|
2
|
+
import type { ShikiTransformer } from 'shiki';
|
|
3
|
+
import type { Processor } from 'unified';
|
|
4
|
+
import type { MdcThemeOptions, HighlighterOptions } from '../highlighter/types';
|
|
5
|
+
export type Awaitable<T> = T | Promise<T>;
|
|
6
|
+
export interface MdcConfig {
|
|
7
|
+
/**
|
|
8
|
+
* Hooks for the unified markdown pipeline
|
|
9
|
+
*/
|
|
10
|
+
unified?: {
|
|
11
|
+
/**
|
|
12
|
+
* Custom setup for unified processor before other plugins
|
|
13
|
+
*/
|
|
14
|
+
pre?: (processor: Processor) => Awaitable<void | Processor>;
|
|
15
|
+
/**
|
|
16
|
+
* Custom setup for unified processor after remark but before rehype
|
|
17
|
+
*/
|
|
18
|
+
remark?: (processor: Processor) => Awaitable<void | Processor>;
|
|
19
|
+
/**
|
|
20
|
+
* Custom setup for unified processor after rehype
|
|
21
|
+
*/
|
|
22
|
+
rehype?: (processor: Processor) => Awaitable<void | Processor>;
|
|
23
|
+
/**
|
|
24
|
+
* Custom setup for unified processor after all plugins
|
|
25
|
+
*/
|
|
26
|
+
post?: (processor: Processor) => Awaitable<void | Processor>;
|
|
27
|
+
};
|
|
28
|
+
/**
|
|
29
|
+
* Custom hightlighter, available when `highlighter` is set to `custom`
|
|
30
|
+
*/
|
|
31
|
+
highlighter?: Highlighter;
|
|
32
|
+
/**
|
|
33
|
+
* Hooks for shiki
|
|
34
|
+
*/
|
|
35
|
+
shiki?: {
|
|
36
|
+
/**
|
|
37
|
+
* Get transformers for shiki
|
|
38
|
+
*/
|
|
39
|
+
transformers?: ShikiTransformer[] | ((code: string, lang: string, theme: MdcThemeOptions, options: Partial<HighlighterOptions>) => Awaitable<ShikiTransformer[]>);
|
|
40
|
+
/**
|
|
41
|
+
* Custom setup for shiki instance, only called once on server or client
|
|
42
|
+
*/
|
|
43
|
+
setup?: (highlighter: HighlighterCore) => Awaitable<void>;
|
|
44
|
+
};
|
|
45
|
+
}
|
|
File without changes
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Options as RehypeOption } from 'remark-rehype';
|
|
2
|
-
import type {
|
|
2
|
+
import type { RehypeHighlightOption } from '../highlighter/rehype';
|
|
3
|
+
import type { MdcConfig } from './config';
|
|
3
4
|
export interface RemarkPlugin {
|
|
4
5
|
instance?: any;
|
|
5
6
|
options?: Array<any> | Record<string, any>;
|
|
@@ -16,10 +17,7 @@ export interface MDCParseOptions {
|
|
|
16
17
|
options?: RehypeOption;
|
|
17
18
|
plugins?: Record<string, false | RehypePlugin>;
|
|
18
19
|
};
|
|
19
|
-
highlight?:
|
|
20
|
-
theme?: Theme;
|
|
21
|
-
highlighter?: Highlighter;
|
|
22
|
-
} | false;
|
|
20
|
+
highlight?: RehypeHighlightOption | false;
|
|
23
21
|
toc?: {
|
|
24
22
|
/**
|
|
25
23
|
* Maximum heading depth to include in the table of contents.
|
|
@@ -27,4 +25,8 @@ export interface MDCParseOptions {
|
|
|
27
25
|
depth?: number;
|
|
28
26
|
searchDepth?: number;
|
|
29
27
|
};
|
|
28
|
+
/**
|
|
29
|
+
* Inline mdc.config.ts
|
|
30
|
+
*/
|
|
31
|
+
configs?: MdcConfig[];
|
|
30
32
|
}
|
|
@@ -6,7 +6,7 @@ import type { MDCElement, MDCNode } from '../types';
|
|
|
6
6
|
export declare const TEXT_TAGS: string[];
|
|
7
7
|
/**
|
|
8
8
|
* Check virtual node's tag
|
|
9
|
-
* @param vnode
|
|
9
|
+
* @param vnode Virtual node from Vue virtual DOM
|
|
10
10
|
* @param tag tag name
|
|
11
11
|
* @returns `true` it the virtual node match the tag
|
|
12
12
|
*/
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BuiltinTheme } from 'shiki';
|
|
2
|
+
|
|
3
|
+
type MdcThemeOptions = BuiltinTheme | string | Record<string, BuiltinTheme | string>;
|
|
4
|
+
interface HighlighterOptions {
|
|
5
|
+
highlights?: number[];
|
|
6
|
+
meta?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type { HighlighterOptions as H, MdcThemeOptions as M };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { BuiltinTheme } from 'shiki';
|
|
2
|
+
|
|
3
|
+
type MdcThemeOptions = BuiltinTheme | string | Record<string, BuiltinTheme | string>;
|
|
4
|
+
interface HighlighterOptions {
|
|
5
|
+
highlights?: number[];
|
|
6
|
+
meta?: string;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
export type { HighlighterOptions as H, MdcThemeOptions as M };
|
package/dist/types.d.mts
CHANGED
package/dist/types.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/mdc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "Nuxt MDC module",
|
|
5
5
|
"repository": "nuxt-modules/mdc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -11,6 +11,11 @@
|
|
|
11
11
|
"import": "./dist/module.mjs",
|
|
12
12
|
"require": "./dist/module.cjs"
|
|
13
13
|
},
|
|
14
|
+
"./config": {
|
|
15
|
+
"types": "./dist/config.d.ts",
|
|
16
|
+
"import": "./dist/config.mjs",
|
|
17
|
+
"require": "./dist/config.cjs"
|
|
18
|
+
},
|
|
14
19
|
"./runtime": "./dist/runtime/index.mjs",
|
|
15
20
|
"./dist/runtime": "./dist/runtime/index.mjs",
|
|
16
21
|
"./runtime/*": "./dist/runtime/*.mjs",
|
|
@@ -21,6 +26,17 @@
|
|
|
21
26
|
"files": [
|
|
22
27
|
"dist"
|
|
23
28
|
],
|
|
29
|
+
"typesVersions": {
|
|
30
|
+
"*": {
|
|
31
|
+
"*": [
|
|
32
|
+
"./dist/*",
|
|
33
|
+
"./dist/index.d.ts"
|
|
34
|
+
],
|
|
35
|
+
"config": [
|
|
36
|
+
"./dist/config.d.ts"
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
},
|
|
24
40
|
"scripts": {
|
|
25
41
|
"prepack": "nuxt-module-build prepare; nuxt-module-build",
|
|
26
42
|
"build": "nuxt-module-build prepare; nuxt-module-build build",
|
|
@@ -34,11 +50,13 @@
|
|
|
34
50
|
"test:watch": "vitest watch"
|
|
35
51
|
},
|
|
36
52
|
"dependencies": {
|
|
37
|
-
"@nuxt/kit": "^3.
|
|
38
|
-
"@
|
|
53
|
+
"@nuxt/kit": "^3.10.0",
|
|
54
|
+
"@shikijs/transformers": "^1.0.0-beta.6",
|
|
55
|
+
"@types/hast": "^3.0.4",
|
|
39
56
|
"@types/mdast": "^4.0.3",
|
|
40
57
|
"@vue/compiler-core": "^3.4.15",
|
|
41
58
|
"consola": "^3.2.3",
|
|
59
|
+
"debug": "^4.3.4",
|
|
42
60
|
"defu": "^6.1.4",
|
|
43
61
|
"destr": "^2.0.2",
|
|
44
62
|
"detab": "^3.0.2",
|
|
@@ -47,7 +65,9 @@
|
|
|
47
65
|
"mdast-util-to-hast": "^13.1.0",
|
|
48
66
|
"micromark-util-sanitize-uri": "^2.0.0",
|
|
49
67
|
"ohash": "^1.1.3",
|
|
50
|
-
"
|
|
68
|
+
"parse5": "^7.1.2",
|
|
69
|
+
"pathe": "^1.1.2",
|
|
70
|
+
"property-information": "^6.4.1",
|
|
51
71
|
"rehype-external-links": "^3.0.0",
|
|
52
72
|
"rehype-raw": "^7.0.0",
|
|
53
73
|
"rehype-slug": "^6.0.0",
|
|
@@ -55,12 +75,11 @@
|
|
|
55
75
|
"rehype-sort-attributes": "^5.0.0",
|
|
56
76
|
"remark-emoji": "^4.0.1",
|
|
57
77
|
"remark-gfm": "^4.0.0",
|
|
58
|
-
"remark-mdc": "^3.0.
|
|
78
|
+
"remark-mdc": "^3.0.2",
|
|
59
79
|
"remark-parse": "^11.0.0",
|
|
60
80
|
"remark-rehype": "^11.1.0",
|
|
61
81
|
"scule": "^1.2.0",
|
|
62
|
-
"
|
|
63
|
-
"shikiji-transformers": "^0.9.19",
|
|
82
|
+
"shiki": "^1.0.0-beta.6",
|
|
64
83
|
"ufo": "^1.3.2",
|
|
65
84
|
"unified": "^11.0.4",
|
|
66
85
|
"unist-builder": "^4.0.0",
|
|
@@ -71,19 +90,19 @@
|
|
|
71
90
|
"@nuxt/devtools": "latest",
|
|
72
91
|
"@nuxt/eslint-config": "^0.2.0",
|
|
73
92
|
"@nuxt/module-builder": "^0.5.5",
|
|
74
|
-
"@nuxt/schema": "^3.
|
|
75
|
-
"@nuxt/test-utils": "^3.
|
|
76
|
-
"@nuxt/ui": "^2.
|
|
93
|
+
"@nuxt/schema": "^3.10.0",
|
|
94
|
+
"@nuxt/test-utils": "^3.11.0",
|
|
95
|
+
"@nuxt/ui": "^2.13.0",
|
|
77
96
|
"@types/mdurl": "^1.0.5",
|
|
78
|
-
"@types/node": "^20.11.
|
|
97
|
+
"@types/node": "^20.11.16",
|
|
79
98
|
"changelogen": "^0.5.5",
|
|
80
99
|
"eslint": "^8.56.0",
|
|
81
|
-
"nuxt": "^3.
|
|
100
|
+
"nuxt": "^3.10.0",
|
|
82
101
|
"rehype": "^13.0.1",
|
|
83
|
-
"release-it": "^17.0.
|
|
84
|
-
"vitest": "^1.2.
|
|
102
|
+
"release-it": "^17.0.3",
|
|
103
|
+
"vitest": "^1.2.2"
|
|
85
104
|
},
|
|
86
|
-
"packageManager": "pnpm@8.
|
|
105
|
+
"packageManager": "pnpm@8.15.1",
|
|
87
106
|
"release-it": {
|
|
88
107
|
"git": {
|
|
89
108
|
"commitMessage": "chore(release): release v${version}"
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import { loadWasm } from "shikiji";
|
|
2
|
-
import { eventHandler, getQuery, lazyEventHandler } from "h3";
|
|
3
|
-
import { useShikiHighlighter } from "./highlighter.mjs";
|
|
4
|
-
import { useRuntimeConfig } from "#imports";
|
|
5
|
-
export default lazyEventHandler(async () => {
|
|
6
|
-
const { highlight } = useRuntimeConfig().mdc;
|
|
7
|
-
await loadWasm(
|
|
8
|
-
(imports) => import("shikiji/onig.wasm").then((mod) => mod.default(imports)).then((exports) => ({ exports }))
|
|
9
|
-
);
|
|
10
|
-
const shiki = useShikiHighlighter(highlight);
|
|
11
|
-
return eventHandler(async (event) => {
|
|
12
|
-
const { code, lang, theme: themeString, highlights: highlightsString } = getQuery(event);
|
|
13
|
-
const theme = JSON.parse(themeString);
|
|
14
|
-
const highlights = highlightsString ? JSON.parse(highlightsString) : void 0;
|
|
15
|
-
return await shiki.getHighlightedAST(code, lang, theme, { highlights });
|
|
16
|
-
});
|
|
17
|
-
});
|
|
@@ -1,5 +0,0 @@
|
|
|
1
|
-
import type { HighlightResult, HighlighterOptions, Theme } from './types';
|
|
2
|
-
import type { BuiltinLanguage } from 'shikiji';
|
|
3
|
-
export declare const useShikiHighlighter: (opts?: any) => {
|
|
4
|
-
getHighlightedAST: (code: string, lang: BuiltinLanguage, theme: Theme, opts?: Partial<HighlighterOptions>) => Promise<HighlightResult>;
|
|
5
|
-
};
|