mdast-util-to-vnode 0.1.0 → 0.2.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/README.md CHANGED
@@ -92,7 +92,11 @@ 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
- interface ToVNodeOptions {
96
- components?: Partial<Record<Nodes['type'], Component>>
95
+ export type ComponentReturn = [Component, Record<string, any> | undefined]
96
+
97
+ export interface ToVNodeOptions {
98
+ components?: Partial<Record<Nodes['type'], Component |
99
+ ComponentReturn |
100
+ ((node: Node) => ComponentReturn)>>
97
101
  }
98
102
  ```
package/dist/index.d.ts CHANGED
@@ -1,7 +1,8 @@
1
1
  import { Node, Nodes, Root } from 'mdast';
2
2
  import { Component, VNode } from 'vue';
3
+ export type ComponentReturn = [Component, Record<string, any> | undefined];
3
4
  export interface ToVNodeOptions {
4
- components?: Partial<Record<Nodes['type'], Component>>;
5
+ components?: Partial<Record<Nodes['type'], Component | ComponentReturn | ((node: Node) => ComponentReturn)>>;
5
6
  }
6
7
  export declare function toVNode(node: Root, options?: ToVNodeOptions): VNode<import('vue').RendererNode, import('vue').RendererElement, {
7
8
  [key: string]: any;
package/dist/index.js CHANGED
@@ -1,176 +1,216 @@
1
- import { h as e, Text as i } from "vue";
2
- function u(t, l) {
3
- return l.reduce((r, c) => (r[c] = t[c], r), {});
1
+ import { h as e, Text as b } from "vue";
2
+ function p(r) {
3
+ return Array.isArray(r);
4
4
  }
5
- function p(t, l = {}) {
6
- return s(t, l);
5
+ function y(r) {
6
+ return typeof r == "object" && r !== null;
7
7
  }
8
- function s(t, l = {}) {
8
+ function f(r) {
9
+ return typeof r == "function";
10
+ }
11
+ function n(r) {
12
+ return y(r) && !p(r) && !f(r);
13
+ }
14
+ function l(r, ...s) {
15
+ if (!n(r))
16
+ return r;
17
+ const t = s.filter((c) => n(c));
18
+ if (!t.length)
19
+ return r;
20
+ const a = t.shift();
21
+ for (const c in a)
22
+ n(a[c]) ? (Object.prototype.hasOwnProperty.call(r, c) || Object.assign(r, { [c]: {} }), l(r[c], a[c])) : Object.assign(r, { [c]: a[c] });
23
+ return l(r, ...t);
24
+ }
25
+ function i(r, s) {
26
+ return s.reduce((t, a) => (t[a] = r[a], t), {});
27
+ }
28
+ function g(r, s = {}) {
29
+ return m(r, s);
30
+ }
31
+ function m(r, s = {}) {
9
32
  var c;
10
- const r = (c = l.components) == null ? void 0 : c[t.type];
11
- switch (t.type) {
33
+ let t = (c = s.components) == null ? void 0 : c[r.type], a = {};
34
+ if (f(t)) {
35
+ const [o, h] = t(r);
36
+ t = o, a = h ?? {};
37
+ } else p(t) && (a = t[1] ?? {}, t = t[0]);
38
+ switch (r.type) {
12
39
  case "blockquote":
13
40
  return e(
14
- r ?? "blockquote",
15
- a(t)
41
+ t ?? "blockquote",
42
+ a,
43
+ u(r)
16
44
  );
17
45
  case "break":
18
46
  return e(
19
- r ?? "br"
47
+ t ?? "br",
48
+ a
20
49
  );
21
50
  case "code":
22
- return r ? e(
23
- r,
24
- u(t, ["lang", "meta", "value"])
51
+ return t ? e(
52
+ t,
53
+ l(i(r, ["lang", "meta", "value"]), a)
25
54
  ) : e(
26
55
  "pre",
27
56
  {
28
- dataLang: t.lang,
29
- dataMeta: t.meta
57
+ dataLang: r.lang,
58
+ dataMeta: r.meta
30
59
  },
31
- e("code", t.value)
60
+ e("code", r.value)
32
61
  );
33
62
  case "delete":
34
63
  return e(
35
- r ?? "s",
36
- a(t)
64
+ t ?? "s",
65
+ a,
66
+ u(r)
37
67
  );
38
68
  case "emphasis":
39
69
  return e(
40
- r ?? "em",
41
- a(t)
70
+ t ?? "em",
71
+ a,
72
+ u(r)
42
73
  );
43
74
  case "heading":
44
- return r ? e(
45
- r,
46
- u(t, ["depth"])
75
+ return t ? e(
76
+ t,
77
+ l(i(r, ["depth"]), a)
47
78
  ) : e(
48
- `h${t.depth}`,
49
- a(t)
79
+ `h${r.depth}`,
80
+ u(r)
50
81
  );
51
82
  case "html":
52
- return r ? e(
53
- r,
54
- u(t, ["value"])
83
+ return t ? e(
84
+ t,
85
+ l(i(r, ["value"]), a)
55
86
  ) : e(
56
87
  "div",
57
88
  {
58
- innerHTML: t.value
89
+ innerHTML: r.value
59
90
  }
60
91
  );
61
92
  case "image":
62
- return r ? e(
63
- r,
64
- u(t, ["url", "alt", "title"])
93
+ return t ? e(
94
+ t,
95
+ l(i(r, ["url", "alt", "title"]), a)
65
96
  ) : e(
66
97
  "img",
67
98
  {
68
- src: t.url,
69
- alt: t.alt,
70
- title: t.title
99
+ src: r.url,
100
+ alt: r.alt,
101
+ title: r.title
71
102
  }
72
103
  );
73
104
  case "inlineCode":
74
- return r ? e(
75
- r,
76
- u(t, ["value"])
105
+ return t ? e(
106
+ t,
107
+ l(i(r, ["value"]), a)
77
108
  ) : e(
78
109
  "code",
79
- t.value
110
+ r.value
80
111
  );
81
112
  case "link":
82
- return r ? e(
83
- r,
84
- u(t, ["url", "title"]),
85
- a(t)
113
+ return t ? e(
114
+ t,
115
+ l(i(r, ["url", "title"]), a),
116
+ u(r)
86
117
  ) : e(
87
118
  "a",
88
119
  {
89
- href: t.url
120
+ href: r.url
90
121
  },
91
- a(t)
122
+ u(r)
92
123
  );
93
124
  case "list":
94
- return r ? e(
95
- r,
96
- u(t, ["ordered", "spread", "start"]),
97
- a(t)
125
+ return t ? e(
126
+ t,
127
+ l(i(r, ["ordered", "spread", "start"]), a),
128
+ u(r)
98
129
  ) : e(
99
- t.ordered ? "ol" : "ul",
100
- a(t)
130
+ r.ordered ? "ol" : "ul",
131
+ u(r)
101
132
  );
102
133
  case "listItem":
103
- return r ? e(
104
- r,
105
- u(t, ["checked", "spread"]),
106
- a(t)
134
+ return t ? e(
135
+ t,
136
+ l(i(r, ["checked", "spread"]), a),
137
+ u(r)
107
138
  ) : e(
108
139
  "li",
109
- a(t)
140
+ u(r)
110
141
  );
111
142
  case "paragraph":
112
143
  return e(
113
- r ?? "p",
114
- a(t)
144
+ t ?? "p",
145
+ a,
146
+ u(r)
115
147
  );
116
148
  case "root":
117
149
  return e(
118
- r ?? "div",
119
- a(t)
150
+ t ?? "div",
151
+ a,
152
+ u(r)
120
153
  );
121
154
  case "strong":
122
155
  return e(
123
- r ?? "strong",
124
- a(t)
156
+ t ?? "strong",
157
+ a,
158
+ u(r)
125
159
  );
126
160
  case "table":
127
161
  return e(
128
- r ?? "table",
129
- u(t, ["align"]),
130
- a(t)
162
+ t ?? "table",
163
+ l(i(r, ["align"]), a),
164
+ u(r)
131
165
  );
132
166
  case "tableCell":
133
167
  return e(
134
- r ?? "td",
135
- a(t)
168
+ t ?? "td",
169
+ a,
170
+ u(r)
136
171
  );
137
172
  case "tableRow":
138
173
  return e(
139
- r ?? "th",
140
- a(t)
174
+ t ?? "th",
175
+ a,
176
+ u(r)
141
177
  );
142
178
  case "text":
143
179
  return e(
144
- i,
145
- t.value
180
+ b,
181
+ r.value
146
182
  );
147
183
  case "thematicBreak":
148
184
  return e(
149
- r ?? "hr"
185
+ t ?? "hr",
186
+ a
150
187
  );
151
188
  case "yaml":
152
- return r ? e(
153
- r,
154
- {
155
- lang: "yaml",
156
- value: t.value
157
- }
189
+ return t ? e(
190
+ t,
191
+ l(
192
+ {
193
+ lang: "yaml",
194
+ value: r.value
195
+ },
196
+ a
197
+ )
158
198
  ) : e(
159
199
  "pre",
160
200
  {
161
201
  dataLang: "yaml"
162
202
  },
163
- e("code", t.value)
203
+ e("code", r.value)
164
204
  );
165
205
  default:
166
206
  return e(Comment);
167
207
  }
168
208
  }
169
- function a(t, l = {}) {
170
- var r;
171
- return ((r = t.children) == null ? void 0 : r.map((c) => s(c, l))) ?? [];
209
+ function u(r, s = {}) {
210
+ var t;
211
+ return ((t = r.children) == null ? void 0 : t.map((a) => m(a, s))) ?? [];
172
212
  }
173
213
  export {
174
- s as createVNode,
175
- p as toVNode
214
+ m as createVNode,
215
+ g as toVNode
176
216
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "mdast-util-to-vnode",
3
3
  "type": "module",
4
- "version": "0.1.0",
4
+ "version": "0.2.0",
5
5
  "private": false,
6
6
  "packageManager": "pnpm@10.5.2+sha512.da9dc28cd3ff40d0592188235ab25d3202add8a207afbedc682220e4a0029ffbff4562102b9e6e46b4e3f9e8bd53e6d05de48544b0c57d4b0179e22c76d1199b",
7
7
  "description": "mdast utility to get the vue vnode",
@@ -38,8 +38,6 @@
38
38
  "lint": "eslint .",
39
39
  "format": "eslint --fix .",
40
40
  "build": "vite build",
41
- "test": "vitest",
42
- "coverage": "vitest run --coverage",
43
41
  "commit": "git-cz",
44
42
  "release": "bumpp",
45
43
  "prepare": "husky"
@@ -54,8 +52,6 @@
54
52
  "@commitlint/cz-commitlint": "^19.6.1",
55
53
  "@types/mdast": "^4.0.4",
56
54
  "@types/node": "22",
57
- "@vitest/coverage-istanbul": "3.0.6",
58
- "@vitest/coverage-v8": "3.0.6",
59
55
  "bumpp": "^9.10.2",
60
56
  "commitizen": "^4.3.1",
61
57
  "eslint": "^9.18.0",
@@ -68,8 +64,7 @@
68
64
  "unplugin-external": "0.1.0-beta.3",
69
65
  "usexx": "^0.1.0",
70
66
  "vite": "^6.1.1",
71
- "vite-plugin-dts": "^4.5.0",
72
- "vitest": "^3.0.6"
67
+ "vite-plugin-dts": "^4.5.0"
73
68
  },
74
69
  "config": {
75
70
  "commitizen": {