mdast-util-to-vnode 0.0.0 → 0.1.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 liting
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,98 @@
1
+ # mdast-util-to-vnode
2
+
3
+ mdast utility to get the vue vnode
4
+
5
+ ## What is this?
6
+
7
+ This package is a utility that takes [mdast](https://github.com/syntax-tree/mdast) input and turns it into an [Vue.js](https://github.com/vuejs/core) VNode.
8
+
9
+ ## When should I use this?
10
+
11
+ If you want to use Vue.js to render mdast, use it. It is especially useful when you want to render streamed MarkDown strings in AI application development.
12
+
13
+ ## Install
14
+
15
+ ```bash
16
+ npm install mdast-util-to-vnode
17
+ ```
18
+
19
+ ## Use
20
+
21
+ Say we have the following markdown file `example.md`:
22
+
23
+ ```md
24
+ # Heading
25
+
26
+ `mdast-util-to-vnode` is a mdast utility to get the vue vnode.
27
+ ```
28
+
29
+ And our module `example.js` looks as follows:
30
+
31
+ ```js
32
+ import fs from 'node:fs/promises'
33
+ import { fromMarkdown } from 'mdast-util-from-markdown'
34
+ import { toVNode } from 'mdast-util-to-vnode'
35
+
36
+ const doc = await fs.readFile('example.md')
37
+ const vnode = toVNode(fromMarkdown(doc))
38
+
39
+ console.log(vnode)
40
+ ```
41
+
42
+ Now running node example.js yields (some info removed for brevity):
43
+
44
+ ```json
45
+ {
46
+ "type": "div",
47
+ "props": null,
48
+ "key": null,
49
+ "children": [
50
+ {
51
+ "type": "h1",
52
+ "props": null,
53
+ "key": null,
54
+ "children": [
55
+ {
56
+ "props": null,
57
+ "key": null,
58
+ "children": "Heading"
59
+ }
60
+ ]
61
+ },
62
+ {
63
+ "type": "p",
64
+ "props": null,
65
+ "key": null,
66
+ "children": [
67
+ {
68
+ "type": "code",
69
+ "props": null,
70
+ "key": null,
71
+ "children": "mdast-util-to-vnode"
72
+ },
73
+ {
74
+ "props": null,
75
+ "key": null,
76
+ "children": " is a mdast utility to get the vue vnode."
77
+ }
78
+ ]
79
+ }
80
+ ]
81
+ }
82
+ ```
83
+
84
+ ## API
85
+
86
+ This package exports the identifier `toVNode`. There is no default export.
87
+
88
+ ### toVNode(mdast[, options])
89
+
90
+ #### options
91
+
92
+ Support passing in custom Vue components to override mdast nodes.
93
+
94
+ ```ts
95
+ interface ToVNodeOptions {
96
+ components?: Partial<Record<Nodes['type'], Component>>
97
+ }
98
+ ```
@@ -0,0 +1,9 @@
1
+ import { Node, Nodes, Root } from 'mdast';
2
+ import { Component, VNode } from 'vue';
3
+ export interface ToVNodeOptions {
4
+ components?: Partial<Record<Nodes['type'], Component>>;
5
+ }
6
+ export declare function toVNode(node: Root, options?: ToVNodeOptions): VNode<import('vue').RendererNode, import('vue').RendererElement, {
7
+ [key: string]: any;
8
+ }>;
9
+ export declare function createVNode(node: Node, options?: ToVNodeOptions): VNode;
package/dist/index.js ADDED
@@ -0,0 +1,176 @@
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), {});
4
+ }
5
+ function p(t, l = {}) {
6
+ return s(t, l);
7
+ }
8
+ function s(t, l = {}) {
9
+ var c;
10
+ const r = (c = l.components) == null ? void 0 : c[t.type];
11
+ switch (t.type) {
12
+ case "blockquote":
13
+ return e(
14
+ r ?? "blockquote",
15
+ a(t)
16
+ );
17
+ case "break":
18
+ return e(
19
+ r ?? "br"
20
+ );
21
+ case "code":
22
+ return r ? e(
23
+ r,
24
+ u(t, ["lang", "meta", "value"])
25
+ ) : e(
26
+ "pre",
27
+ {
28
+ dataLang: t.lang,
29
+ dataMeta: t.meta
30
+ },
31
+ e("code", t.value)
32
+ );
33
+ case "delete":
34
+ return e(
35
+ r ?? "s",
36
+ a(t)
37
+ );
38
+ case "emphasis":
39
+ return e(
40
+ r ?? "em",
41
+ a(t)
42
+ );
43
+ case "heading":
44
+ return r ? e(
45
+ r,
46
+ u(t, ["depth"])
47
+ ) : e(
48
+ `h${t.depth}`,
49
+ a(t)
50
+ );
51
+ case "html":
52
+ return r ? e(
53
+ r,
54
+ u(t, ["value"])
55
+ ) : e(
56
+ "div",
57
+ {
58
+ innerHTML: t.value
59
+ }
60
+ );
61
+ case "image":
62
+ return r ? e(
63
+ r,
64
+ u(t, ["url", "alt", "title"])
65
+ ) : e(
66
+ "img",
67
+ {
68
+ src: t.url,
69
+ alt: t.alt,
70
+ title: t.title
71
+ }
72
+ );
73
+ case "inlineCode":
74
+ return r ? e(
75
+ r,
76
+ u(t, ["value"])
77
+ ) : e(
78
+ "code",
79
+ t.value
80
+ );
81
+ case "link":
82
+ return r ? e(
83
+ r,
84
+ u(t, ["url", "title"]),
85
+ a(t)
86
+ ) : e(
87
+ "a",
88
+ {
89
+ href: t.url
90
+ },
91
+ a(t)
92
+ );
93
+ case "list":
94
+ return r ? e(
95
+ r,
96
+ u(t, ["ordered", "spread", "start"]),
97
+ a(t)
98
+ ) : e(
99
+ t.ordered ? "ol" : "ul",
100
+ a(t)
101
+ );
102
+ case "listItem":
103
+ return r ? e(
104
+ r,
105
+ u(t, ["checked", "spread"]),
106
+ a(t)
107
+ ) : e(
108
+ "li",
109
+ a(t)
110
+ );
111
+ case "paragraph":
112
+ return e(
113
+ r ?? "p",
114
+ a(t)
115
+ );
116
+ case "root":
117
+ return e(
118
+ r ?? "div",
119
+ a(t)
120
+ );
121
+ case "strong":
122
+ return e(
123
+ r ?? "strong",
124
+ a(t)
125
+ );
126
+ case "table":
127
+ return e(
128
+ r ?? "table",
129
+ u(t, ["align"]),
130
+ a(t)
131
+ );
132
+ case "tableCell":
133
+ return e(
134
+ r ?? "td",
135
+ a(t)
136
+ );
137
+ case "tableRow":
138
+ return e(
139
+ r ?? "th",
140
+ a(t)
141
+ );
142
+ case "text":
143
+ return e(
144
+ i,
145
+ t.value
146
+ );
147
+ case "thematicBreak":
148
+ return e(
149
+ r ?? "hr"
150
+ );
151
+ case "yaml":
152
+ return r ? e(
153
+ r,
154
+ {
155
+ lang: "yaml",
156
+ value: t.value
157
+ }
158
+ ) : e(
159
+ "pre",
160
+ {
161
+ dataLang: "yaml"
162
+ },
163
+ e("code", t.value)
164
+ );
165
+ default:
166
+ return e(Comment);
167
+ }
168
+ }
169
+ function a(t, l = {}) {
170
+ var r;
171
+ return ((r = t.children) == null ? void 0 : r.map((c) => s(c, l))) ?? [];
172
+ }
173
+ export {
174
+ s as createVNode,
175
+ p as toVNode
176
+ };
package/package.json CHANGED
@@ -1,9 +1,87 @@
1
1
  {
2
2
  "name": "mdast-util-to-vnode",
3
- "version": "0.0.0",
4
- "description": "",
3
+ "type": "module",
4
+ "version": "0.1.0",
5
+ "private": false,
6
+ "packageManager": "pnpm@10.5.2+sha512.da9dc28cd3ff40d0592188235ab25d3202add8a207afbedc682220e4a0029ffbff4562102b9e6e46b4e3f9e8bd53e6d05de48544b0c57d4b0179e22c76d1199b",
7
+ "description": "mdast utility to get the vue vnode",
8
+ "author": "litingyes <luz.liting@gmail.com> (https://litingyes.top/)",
5
9
  "license": "MIT",
6
- "dependencies": {
7
- "jiti": "^2.4.2"
10
+ "homepage": "https://github.com/litingyes/mdast-util-to-vnode#readme",
11
+ "bugs": {
12
+ "url": "https://github.com/litingyes/mdast-util-to-vnode/issues"
13
+ },
14
+ "keywords": [
15
+ "unified",
16
+ "remark",
17
+ "mdast",
18
+ "mdast-util",
19
+ "markdown",
20
+ "vue",
21
+ "vnode",
22
+ "stream",
23
+ "ai"
24
+ ],
25
+ "exports": {
26
+ ".": {
27
+ "types": "./dist/index.d.ts",
28
+ "import": "./dist/index.js"
29
+ }
30
+ },
31
+ "main": "./dist/index.js",
32
+ "module": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "files": [
35
+ "dist"
36
+ ],
37
+ "scripts": {
38
+ "lint": "eslint .",
39
+ "format": "eslint --fix .",
40
+ "build": "vite build",
41
+ "test": "vitest",
42
+ "coverage": "vitest run --coverage",
43
+ "commit": "git-cz",
44
+ "release": "bumpp",
45
+ "prepare": "husky"
46
+ },
47
+ "peerDependencies": {
48
+ "vue": "3"
49
+ },
50
+ "devDependencies": {
51
+ "@antfu/eslint-config": "^3.14.0",
52
+ "@commitlint/cli": "^19.6.1",
53
+ "@commitlint/config-conventional": "^19.6.0",
54
+ "@commitlint/cz-commitlint": "^19.6.1",
55
+ "@types/mdast": "^4.0.4",
56
+ "@types/node": "22",
57
+ "@vitest/coverage-istanbul": "3.0.6",
58
+ "@vitest/coverage-v8": "3.0.6",
59
+ "bumpp": "^9.10.2",
60
+ "commitizen": "^4.3.1",
61
+ "eslint": "^9.18.0",
62
+ "eslint-plugin-format": "^1.0.1",
63
+ "husky": "^9.1.7",
64
+ "inquirer": "^12.3.3",
65
+ "lint-staged": "^15.4.3",
66
+ "mdast-util-from-markdown": "^2.0.2",
67
+ "typescript": "^5.7.3",
68
+ "unplugin-external": "0.1.0-beta.3",
69
+ "usexx": "^0.1.0",
70
+ "vite": "^6.1.1",
71
+ "vite-plugin-dts": "^4.5.0",
72
+ "vitest": "^3.0.6"
73
+ },
74
+ "config": {
75
+ "commitizen": {
76
+ "path": "@commitlint/cz-commitlint"
77
+ }
78
+ },
79
+ "commitlint": {
80
+ "extends": [
81
+ "@commitlint/config-conventional"
82
+ ]
83
+ },
84
+ "lint-staged": {
85
+ "*": "eslint --fix"
8
86
  }
9
- }
87
+ }