mdast-util-to-vnode 0.3.0 → 0.3.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/README.md +2 -3
- package/dist/index.d.ts +5 -1
- package/dist/index.js +81 -61
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -92,11 +92,10 @@ This package exports the identifier `toVNode`. There is no default export.
|
|
|
92
92
|
Support passing in custom Vue components to override mdast nodes.
|
|
93
93
|
|
|
94
94
|
```ts
|
|
95
|
-
export type ComponentReturn = [Component, Record<string, any> | undefined]
|
|
95
|
+
export type ComponentReturn = Component | [Component, Record<string, any> | undefined]
|
|
96
96
|
|
|
97
97
|
export interface ToVNodeOptions {
|
|
98
|
-
components?: Partial<Record<Nodes['type'],
|
|
99
|
-
ComponentReturn |
|
|
98
|
+
components?: Partial<Record<Nodes['type'], ComponentReturn |
|
|
100
99
|
((node: Node) => ComponentReturn)>>
|
|
101
100
|
}
|
|
102
101
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -7,4 +7,8 @@ export interface ToVNodeOptions {
|
|
|
7
7
|
export declare function toVNode(node: Root, options?: ToVNodeOptions): VNode<import('vue').RendererNode, import('vue').RendererElement, {
|
|
8
8
|
[key: string]: any;
|
|
9
9
|
}>;
|
|
10
|
-
export
|
|
10
|
+
export interface CreateVNodeContext {
|
|
11
|
+
index: number;
|
|
12
|
+
parent: Node | null;
|
|
13
|
+
}
|
|
14
|
+
export declare function createVNode(node: Node, options: ToVNodeOptions | undefined, context: CreateVNodeContext): VNode;
|
package/dist/index.js
CHANGED
|
@@ -1,42 +1,45 @@
|
|
|
1
|
-
import { h as t, Text as
|
|
2
|
-
function
|
|
1
|
+
import { h as t, Comment as O, Text as j } from "vue";
|
|
2
|
+
function p(r) {
|
|
3
3
|
return Array.isArray(r);
|
|
4
4
|
}
|
|
5
|
-
function
|
|
5
|
+
function C(r) {
|
|
6
6
|
return typeof r == "object" && r !== null;
|
|
7
7
|
}
|
|
8
|
-
function
|
|
8
|
+
function y(r) {
|
|
9
9
|
return typeof r == "function";
|
|
10
10
|
}
|
|
11
|
-
function
|
|
12
|
-
return
|
|
11
|
+
function s(r) {
|
|
12
|
+
return C(r) && !p(r) && !y(r);
|
|
13
13
|
}
|
|
14
|
-
function
|
|
15
|
-
if (!
|
|
14
|
+
function i(r, ...l) {
|
|
15
|
+
if (!s(r))
|
|
16
16
|
return r;
|
|
17
|
-
const
|
|
18
|
-
if (!
|
|
17
|
+
const c = l.filter((a) => s(a));
|
|
18
|
+
if (!c.length)
|
|
19
19
|
return r;
|
|
20
|
-
const
|
|
21
|
-
for (const
|
|
22
|
-
|
|
23
|
-
return
|
|
20
|
+
const e = c.shift();
|
|
21
|
+
for (const a in e)
|
|
22
|
+
s(e[a]) ? (Object.prototype.hasOwnProperty.call(r, a) || Object.assign(r, { [a]: {} }), i(r[a], e[a])) : Object.assign(r, { [a]: e[a] });
|
|
23
|
+
return i(r, ...c);
|
|
24
24
|
}
|
|
25
|
-
function
|
|
26
|
-
return
|
|
25
|
+
function n(r, l) {
|
|
26
|
+
return l.reduce((c, e) => (c[e] = r[e], c), {});
|
|
27
27
|
}
|
|
28
|
-
function
|
|
29
|
-
return
|
|
28
|
+
function N(r, l = {}) {
|
|
29
|
+
return v(r, l, {
|
|
30
|
+
index: 0,
|
|
31
|
+
parent: null
|
|
32
|
+
});
|
|
30
33
|
}
|
|
31
|
-
function
|
|
32
|
-
var
|
|
33
|
-
let e = (
|
|
34
|
-
switch (
|
|
34
|
+
function v(r, l = {}, c) {
|
|
35
|
+
var f, m, h, b, g;
|
|
36
|
+
let e = (f = l.components) == null ? void 0 : f[r.type], a = {};
|
|
37
|
+
switch (y(e) && (e = e(r)), p(e) && (a = e[1] ?? {}, e = e[0]), r.type) {
|
|
35
38
|
case "blockquote":
|
|
36
39
|
return t(
|
|
37
40
|
e ?? "blockquote",
|
|
38
41
|
a,
|
|
39
|
-
|
|
42
|
+
u(r, l)
|
|
40
43
|
);
|
|
41
44
|
case "break":
|
|
42
45
|
return t(
|
|
@@ -46,7 +49,7 @@ function h(r, u = {}) {
|
|
|
46
49
|
case "code":
|
|
47
50
|
return e ? t(
|
|
48
51
|
e,
|
|
49
|
-
|
|
52
|
+
i(n(r, ["lang", "meta", "value"]), a)
|
|
50
53
|
) : t(
|
|
51
54
|
"pre",
|
|
52
55
|
{
|
|
@@ -59,26 +62,26 @@ function h(r, u = {}) {
|
|
|
59
62
|
return t(
|
|
60
63
|
e ?? "s",
|
|
61
64
|
a,
|
|
62
|
-
|
|
65
|
+
u(r, l)
|
|
63
66
|
);
|
|
64
67
|
case "emphasis":
|
|
65
68
|
return t(
|
|
66
69
|
e ?? "em",
|
|
67
70
|
a,
|
|
68
|
-
|
|
71
|
+
u(r, l)
|
|
69
72
|
);
|
|
70
73
|
case "heading":
|
|
71
74
|
return e ? t(
|
|
72
75
|
e,
|
|
73
|
-
|
|
76
|
+
i(n(r, ["depth"]), a)
|
|
74
77
|
) : t(
|
|
75
78
|
`h${r.depth}`,
|
|
76
|
-
|
|
79
|
+
u(r, l)
|
|
77
80
|
);
|
|
78
81
|
case "html":
|
|
79
82
|
return e ? t(
|
|
80
83
|
e,
|
|
81
|
-
|
|
84
|
+
i(n(r, ["value"]), a)
|
|
82
85
|
) : t(
|
|
83
86
|
"div",
|
|
84
87
|
{
|
|
@@ -88,7 +91,7 @@ function h(r, u = {}) {
|
|
|
88
91
|
case "image":
|
|
89
92
|
return e ? t(
|
|
90
93
|
e,
|
|
91
|
-
|
|
94
|
+
i(n(r, ["url", "alt", "title"]), a)
|
|
92
95
|
) : t(
|
|
93
96
|
"img",
|
|
94
97
|
{
|
|
@@ -100,7 +103,7 @@ function h(r, u = {}) {
|
|
|
100
103
|
case "inlineCode":
|
|
101
104
|
return e ? t(
|
|
102
105
|
e,
|
|
103
|
-
|
|
106
|
+
i(n(r, ["value"]), a)
|
|
104
107
|
) : t(
|
|
105
108
|
"code",
|
|
106
109
|
r.value
|
|
@@ -108,72 +111,86 @@ function h(r, u = {}) {
|
|
|
108
111
|
case "link":
|
|
109
112
|
return e ? t(
|
|
110
113
|
e,
|
|
111
|
-
|
|
112
|
-
|
|
114
|
+
i(
|
|
115
|
+
{
|
|
116
|
+
target: "_blank"
|
|
117
|
+
},
|
|
118
|
+
n(r, ["url", "title"]),
|
|
119
|
+
a
|
|
120
|
+
),
|
|
121
|
+
u(r, l)
|
|
113
122
|
) : t(
|
|
114
123
|
"a",
|
|
115
124
|
{
|
|
116
|
-
href: r.url
|
|
125
|
+
href: r.url,
|
|
126
|
+
target: "_blank"
|
|
117
127
|
},
|
|
118
|
-
|
|
128
|
+
u(r, l)
|
|
119
129
|
);
|
|
120
130
|
case "list":
|
|
121
131
|
return e ? t(
|
|
122
132
|
e,
|
|
123
|
-
|
|
124
|
-
|
|
133
|
+
i(n(r, ["ordered", "spread", "start"]), a),
|
|
134
|
+
u(r, l)
|
|
125
135
|
) : t(
|
|
126
136
|
r.ordered ? "ol" : "ul",
|
|
127
|
-
|
|
137
|
+
u(r, l)
|
|
128
138
|
);
|
|
129
139
|
case "listItem":
|
|
130
140
|
return e ? t(
|
|
131
141
|
e,
|
|
132
|
-
|
|
133
|
-
|
|
142
|
+
i(n(r, ["checked", "spread"]), a),
|
|
143
|
+
u(r, l)
|
|
134
144
|
) : t(
|
|
135
145
|
"li",
|
|
136
|
-
|
|
146
|
+
u(r, l)
|
|
137
147
|
);
|
|
138
148
|
case "paragraph":
|
|
139
149
|
return t(
|
|
140
150
|
e ?? "p",
|
|
141
151
|
a,
|
|
142
|
-
|
|
152
|
+
u(r, l)
|
|
143
153
|
);
|
|
144
154
|
case "root":
|
|
145
155
|
return t(
|
|
146
156
|
e ?? "div",
|
|
147
157
|
a,
|
|
148
|
-
|
|
158
|
+
u(r, l)
|
|
149
159
|
);
|
|
150
160
|
case "strong":
|
|
151
161
|
return t(
|
|
152
162
|
e ?? "strong",
|
|
153
163
|
a,
|
|
154
|
-
|
|
164
|
+
u(r, l)
|
|
155
165
|
);
|
|
156
166
|
case "table":
|
|
157
167
|
return t(
|
|
158
168
|
e ?? "table",
|
|
159
|
-
s(i(r, ["align"]), a),
|
|
160
|
-
c(r, u)
|
|
161
|
-
);
|
|
162
|
-
case "tableCell":
|
|
163
|
-
return t(
|
|
164
|
-
e ?? "td",
|
|
165
169
|
a,
|
|
166
|
-
|
|
170
|
+
u(r, l)
|
|
167
171
|
);
|
|
168
172
|
case "tableRow":
|
|
173
|
+
return e ? t(
|
|
174
|
+
e,
|
|
175
|
+
i(a, {
|
|
176
|
+
index: c.index,
|
|
177
|
+
align: ((m = c.parent.align) == null ? void 0 : m[c.index]) ?? "left"
|
|
178
|
+
}),
|
|
179
|
+
u(r, l)
|
|
180
|
+
) : t("tr", {
|
|
181
|
+
align: ((h = c.parent.align) == null ? void 0 : h[c.index]) ?? "left"
|
|
182
|
+
}, u(r, l));
|
|
183
|
+
case "tableCell": {
|
|
184
|
+
const k = ((g = (b = c.parent.position) == null ? void 0 : b.start) == null ? void 0 : g.offset) === 0;
|
|
169
185
|
return t(
|
|
170
|
-
e ?? "th",
|
|
186
|
+
e ?? (k ? "th" : "td"),
|
|
171
187
|
a,
|
|
172
|
-
|
|
188
|
+
u(r, l)
|
|
173
189
|
);
|
|
190
|
+
}
|
|
174
191
|
case "text":
|
|
175
192
|
return t(
|
|
176
|
-
|
|
193
|
+
j,
|
|
177
194
|
r.value
|
|
178
195
|
);
|
|
179
196
|
case "thematicBreak":
|
|
@@ -184,7 +201,7 @@ function h(r, u = {}) {
|
|
|
184
201
|
case "yaml":
|
|
185
202
|
return e ? t(
|
|
186
203
|
e,
|
|
187
|
-
|
|
204
|
+
i(
|
|
188
205
|
{
|
|
189
206
|
lang: "yaml",
|
|
190
207
|
value: r.value
|
|
@@ -199,14 +216,17 @@ function h(r, u = {}) {
|
|
|
199
216
|
t("code", r.value)
|
|
200
217
|
);
|
|
201
218
|
default:
|
|
202
|
-
return t(
|
|
219
|
+
return t(O, JSON.stringify(r));
|
|
203
220
|
}
|
|
204
221
|
}
|
|
205
|
-
function
|
|
206
|
-
var
|
|
207
|
-
return ((
|
|
222
|
+
function u(r, l = {}) {
|
|
223
|
+
var c;
|
|
224
|
+
return ((c = r.children) == null ? void 0 : c.map((e, a) => v(e, l, {
|
|
225
|
+
index: a,
|
|
226
|
+
parent: r
|
|
227
|
+
}))) ?? [];
|
|
208
228
|
}
|
|
209
229
|
export {
|
|
210
|
-
|
|
211
|
-
|
|
230
|
+
v as createVNode,
|
|
231
|
+
N as toVNode
|
|
212
232
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mdast-util-to-vnode",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.3.
|
|
4
|
+
"version": "0.3.2",
|
|
5
5
|
"private": false,
|
|
6
6
|
"packageManager": "pnpm@10.5.2+sha512.da9dc28cd3ff40d0592188235ab25d3202add8a207afbedc682220e4a0029ffbff4562102b9e6e46b4e3f9e8bd53e6d05de48544b0c57d4b0179e22c76d1199b",
|
|
7
7
|
"description": "mdast utility to get the vue vnode",
|