@nuxtjs/mdc 0.2.9 → 0.3.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/module.json +1 -1
- package/dist/runtime/components/MDCRenderer.vue.d.ts +1 -1
- 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/highlighter.d.ts +1 -1
- package/dist/runtime/shiki/highlighter.mjs +45 -26
- package/package.json +13 -12
package/dist/module.json
CHANGED
|
@@ -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
|
};
|
|
@@ -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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nuxtjs/mdc",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "Nuxt MDC module",
|
|
5
5
|
"repository": "nuxt-modules/mdc",
|
|
6
6
|
"license": "MIT",
|
|
@@ -37,7 +37,7 @@
|
|
|
37
37
|
"@nuxt/kit": "^3.8.2",
|
|
38
38
|
"@types/hast": "^3.0.3",
|
|
39
39
|
"@types/mdast": "^4.0.3",
|
|
40
|
-
"@vue/compiler-core": "^3.3.
|
|
40
|
+
"@vue/compiler-core": "^3.3.13",
|
|
41
41
|
"consola": "^3.2.3",
|
|
42
42
|
"defu": "^6.1.3",
|
|
43
43
|
"destr": "^2.0.2",
|
|
@@ -49,17 +49,18 @@
|
|
|
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": "^
|
|
57
|
+
"remark-gfm": "^4.0.0",
|
|
58
|
+
"remark-mdc": "^3.0.0",
|
|
59
|
+
"remark-parse": "^11.0.0",
|
|
60
|
+
"remark-rehype": "^11.0.0",
|
|
61
61
|
"scule": "^1.1.1",
|
|
62
|
-
"shikiji": "^0.9.
|
|
62
|
+
"shikiji": "^0.9.10",
|
|
63
|
+
"shikiji-transformers": "^0.9.10",
|
|
63
64
|
"ufo": "^1.3.2",
|
|
64
65
|
"unified": "^11.0.4",
|
|
65
66
|
"unist-builder": "^4.0.0",
|
|
@@ -70,16 +71,16 @@
|
|
|
70
71
|
"@nuxt/eslint-config": "^0.2.0",
|
|
71
72
|
"@nuxt/module-builder": "^0.5.4",
|
|
72
73
|
"@nuxt/schema": "^3.8.2",
|
|
73
|
-
"@nuxt/test-utils": "^3.
|
|
74
|
+
"@nuxt/test-utils": "^3.9.0",
|
|
74
75
|
"@nuxt/ui": "^2.11.1",
|
|
75
76
|
"@types/mdurl": "^1.0.5",
|
|
76
|
-
"@types/node": "^20.10.
|
|
77
|
+
"@types/node": "^20.10.5",
|
|
77
78
|
"changelogen": "^0.5.5",
|
|
78
|
-
"eslint": "^8.
|
|
79
|
+
"eslint": "^8.56.0",
|
|
79
80
|
"nuxt": "^3.8.2",
|
|
80
81
|
"rehype": "^13.0.1",
|
|
81
82
|
"release-it": "^17.0.1",
|
|
82
|
-
"vitest": "^1.0
|
|
83
|
+
"vitest": "^1.1.0"
|
|
83
84
|
},
|
|
84
85
|
"packageManager": "pnpm@8.12.1",
|
|
85
86
|
"release-it": {
|