@markdown-next/vue 0.0.1-alpha
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 +21 -0
- package/dist/components/MarkdownRenderer.d.ts +66 -0
- package/dist/components/MarkdownWorkerPoll.d.ts +3 -0
- package/dist/context.d.ts +9 -0
- package/dist/hooks/useMarkdownParser.d.ts +5 -0
- package/dist/hooks/useMarkdownRender.d.ts +4 -0
- package/dist/hooks/useMarkdownWorkerPool.d.ts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/index.mjs +513 -0
- package/dist/render/hastToVue.d.ts +4 -0
- package/dist/styles/themeGithub.d.ts +3 -0
- package/dist/types.d.ts +29 -0
- package/dist/utils/toError.d.ts +1 -0
- package/package.json +62 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 UnboundedWeb
|
|
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.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
import type { PropType } from 'vue';
|
|
2
|
+
import type { ParserOptions } from '@markdown-next/parser';
|
|
3
|
+
import type { MarkdownComponent, MarkdownComponents } from '../types';
|
|
4
|
+
export declare const MarkdownRenderer: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
5
|
+
markdown: {
|
|
6
|
+
type: StringConstructor;
|
|
7
|
+
required: true;
|
|
8
|
+
};
|
|
9
|
+
parserOptions: {
|
|
10
|
+
type: PropType<ParserOptions>;
|
|
11
|
+
required: false;
|
|
12
|
+
default: undefined;
|
|
13
|
+
};
|
|
14
|
+
components: {
|
|
15
|
+
type: PropType<MarkdownComponents>;
|
|
16
|
+
required: false;
|
|
17
|
+
default: undefined;
|
|
18
|
+
};
|
|
19
|
+
codeRenderer: {
|
|
20
|
+
type: PropType<MarkdownComponent>;
|
|
21
|
+
required: false;
|
|
22
|
+
default: undefined;
|
|
23
|
+
};
|
|
24
|
+
dynamic: {
|
|
25
|
+
type: BooleanConstructor;
|
|
26
|
+
default: boolean;
|
|
27
|
+
};
|
|
28
|
+
debounceMs: {
|
|
29
|
+
type: NumberConstructor;
|
|
30
|
+
default: number;
|
|
31
|
+
};
|
|
32
|
+
}>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
33
|
+
markdown: {
|
|
34
|
+
type: StringConstructor;
|
|
35
|
+
required: true;
|
|
36
|
+
};
|
|
37
|
+
parserOptions: {
|
|
38
|
+
type: PropType<ParserOptions>;
|
|
39
|
+
required: false;
|
|
40
|
+
default: undefined;
|
|
41
|
+
};
|
|
42
|
+
components: {
|
|
43
|
+
type: PropType<MarkdownComponents>;
|
|
44
|
+
required: false;
|
|
45
|
+
default: undefined;
|
|
46
|
+
};
|
|
47
|
+
codeRenderer: {
|
|
48
|
+
type: PropType<MarkdownComponent>;
|
|
49
|
+
required: false;
|
|
50
|
+
default: undefined;
|
|
51
|
+
};
|
|
52
|
+
dynamic: {
|
|
53
|
+
type: BooleanConstructor;
|
|
54
|
+
default: boolean;
|
|
55
|
+
};
|
|
56
|
+
debounceMs: {
|
|
57
|
+
type: NumberConstructor;
|
|
58
|
+
default: number;
|
|
59
|
+
};
|
|
60
|
+
}>> & Readonly<{}>, {
|
|
61
|
+
parserOptions: ParserOptions;
|
|
62
|
+
codeRenderer: MarkdownComponent;
|
|
63
|
+
components: MarkdownComponents;
|
|
64
|
+
dynamic: boolean;
|
|
65
|
+
debounceMs: number;
|
|
66
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import type { ComputedRef, InjectionKey } from 'vue';
|
|
2
|
+
import type { ParserWorkerPool } from '@markdown-next/parser';
|
|
3
|
+
import type { MarkdownRenderOptions } from './types';
|
|
4
|
+
export interface MarkdownWorkerContext {
|
|
5
|
+
pool: ParserWorkerPool;
|
|
6
|
+
renderOptions: ComputedRef<MarkdownRenderOptions | undefined>;
|
|
7
|
+
forceRenderOptions: ComputedRef<boolean>;
|
|
8
|
+
}
|
|
9
|
+
export declare const markdownWorkerContextKey: InjectionKey<MarkdownWorkerContext>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ParserOptions } from '@markdown-next/parser';
|
|
2
|
+
import type { MarkdownRenderOptions, UseMarkdownResult } from '../types';
|
|
3
|
+
import type { ShallowRef, VNodeChild } from 'vue';
|
|
4
|
+
import { type MaybeRef } from './useMarkdownRender';
|
|
5
|
+
export declare function useMarkdownParser(markdown: MaybeRef<string>, parserOptions?: ParserOptions, renderOptions?: MaybeRef<MarkdownRenderOptions | undefined>): UseMarkdownResult<ShallowRef<VNodeChild | null>>;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Ref, ShallowRef, VNodeChild } from 'vue';
|
|
2
|
+
import type { MarkdownRenderOptions, UseMarkdownResult } from '../types';
|
|
3
|
+
export type MaybeRef<T> = T | Ref<T>;
|
|
4
|
+
export declare function useMarkdownRender(markdown: MaybeRef<string>, render: (value: string, options?: MarkdownRenderOptions) => Promise<VNodeChild>, renderOptions?: MaybeRef<MarkdownRenderOptions | undefined>): UseMarkdownResult<ShallowRef<VNodeChild | null>>;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { ParserWorkerPool } from '@markdown-next/parser';
|
|
2
|
+
import type { MarkdownRenderOptions, UseMarkdownResult } from '../types';
|
|
3
|
+
import type { ShallowRef, VNodeChild } from 'vue';
|
|
4
|
+
import { type MaybeRef } from './useMarkdownRender';
|
|
5
|
+
export declare function useMarkdownWorkerPool(markdown: MaybeRef<string>, pool: ParserWorkerPool, renderOptions?: MaybeRef<MarkdownRenderOptions | undefined>): UseMarkdownResult<ShallowRef<VNodeChild | null>>;
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { MarkdownRenderer } from './components/MarkdownRenderer';
|
|
2
|
+
export { MarkdownWorkerPoll } from './components/MarkdownWorkerPoll';
|
|
3
|
+
export { useMarkdownParser } from './hooks/useMarkdownParser';
|
|
4
|
+
export { useMarkdownWorkerPool } from './hooks/useMarkdownWorkerPool';
|
|
5
|
+
export type { MarkdownComponent, MarkdownComponents, MarkdownRenderOptions, MarkdownRendererProps, MarkdownWorkerPollProps, UseMarkdownResult, } from './types';
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,513 @@
|
|
|
1
|
+
import { h, Fragment as W, shallowRef as O, ref as k, watch as v, unref as x, onBeforeUnmount as C, defineComponent as T, useAttrs as F, toRef as E, inject as L, computed as y, onErrorCaptured as j, createVNode as g, mergeProps as H, createTextVNode as b, provide as J } from "vue";
|
|
2
|
+
import { createParser as X, createWorkerPool as G } from "@markdown-next/parser";
|
|
3
|
+
const R = Symbol("MarkdownWorkerPoll"), I = {
|
|
4
|
+
color: "#1f2328",
|
|
5
|
+
backgroundColor: "#ffffff",
|
|
6
|
+
fontFamily: '-apple-system, BlinkMacSystemFont, "Segoe UI", "Noto Sans", Helvetica, Arial, sans-serif',
|
|
7
|
+
fontSize: "16px",
|
|
8
|
+
lineHeight: "1.5",
|
|
9
|
+
wordWrap: "break-word"
|
|
10
|
+
}, M = {
|
|
11
|
+
h1: {
|
|
12
|
+
fontSize: "2em",
|
|
13
|
+
fontWeight: 600,
|
|
14
|
+
margin: "0.67em 0",
|
|
15
|
+
paddingBottom: "0.3em",
|
|
16
|
+
borderBottom: "1px solid #d0d7de"
|
|
17
|
+
},
|
|
18
|
+
h2: {
|
|
19
|
+
fontSize: "1.5em",
|
|
20
|
+
fontWeight: 600,
|
|
21
|
+
margin: "0.83em 0",
|
|
22
|
+
paddingBottom: "0.3em",
|
|
23
|
+
borderBottom: "1px solid #d0d7de"
|
|
24
|
+
},
|
|
25
|
+
h3: {
|
|
26
|
+
fontSize: "1.25em",
|
|
27
|
+
fontWeight: 600,
|
|
28
|
+
margin: "1em 0"
|
|
29
|
+
},
|
|
30
|
+
h4: {
|
|
31
|
+
fontSize: "1em",
|
|
32
|
+
fontWeight: 600,
|
|
33
|
+
margin: "1em 0"
|
|
34
|
+
},
|
|
35
|
+
h5: {
|
|
36
|
+
fontSize: "0.875em",
|
|
37
|
+
fontWeight: 600,
|
|
38
|
+
margin: "1em 0"
|
|
39
|
+
},
|
|
40
|
+
h6: {
|
|
41
|
+
fontSize: "0.85em",
|
|
42
|
+
fontWeight: 600,
|
|
43
|
+
margin: "1em 0",
|
|
44
|
+
color: "#656d76"
|
|
45
|
+
},
|
|
46
|
+
p: {
|
|
47
|
+
marginTop: 0,
|
|
48
|
+
marginBottom: "16px"
|
|
49
|
+
},
|
|
50
|
+
blockquote: {
|
|
51
|
+
padding: "0 1em",
|
|
52
|
+
color: "#656d76",
|
|
53
|
+
borderLeft: "0.25em solid #d0d7de",
|
|
54
|
+
margin: "0 0 16px 0"
|
|
55
|
+
},
|
|
56
|
+
ul: {
|
|
57
|
+
marginTop: 0,
|
|
58
|
+
marginBottom: "16px",
|
|
59
|
+
paddingLeft: "2em"
|
|
60
|
+
},
|
|
61
|
+
ol: {
|
|
62
|
+
marginTop: 0,
|
|
63
|
+
marginBottom: "16px",
|
|
64
|
+
paddingLeft: "2em"
|
|
65
|
+
},
|
|
66
|
+
li: {
|
|
67
|
+
marginTop: "0.25em"
|
|
68
|
+
},
|
|
69
|
+
table: {
|
|
70
|
+
borderCollapse: "collapse",
|
|
71
|
+
width: "100%",
|
|
72
|
+
marginBottom: "16px"
|
|
73
|
+
},
|
|
74
|
+
th: {
|
|
75
|
+
border: "1px solid #d0d7de",
|
|
76
|
+
padding: "6px 13px",
|
|
77
|
+
backgroundColor: "#f6f8fa",
|
|
78
|
+
fontWeight: 600
|
|
79
|
+
},
|
|
80
|
+
td: {
|
|
81
|
+
border: "1px solid #d0d7de",
|
|
82
|
+
padding: "6px 13px"
|
|
83
|
+
},
|
|
84
|
+
pre: {
|
|
85
|
+
backgroundColor: "#f6f8fa",
|
|
86
|
+
borderRadius: "6px",
|
|
87
|
+
padding: "16px",
|
|
88
|
+
overflow: "auto",
|
|
89
|
+
fontSize: "85%",
|
|
90
|
+
lineHeight: "1.45",
|
|
91
|
+
marginBottom: "16px"
|
|
92
|
+
},
|
|
93
|
+
code: {
|
|
94
|
+
fontFamily: 'SFMono-Regular, Consolas, "Liberation Mono", Menlo, monospace',
|
|
95
|
+
fontSize: "85%",
|
|
96
|
+
backgroundColor: "rgba(175, 184, 193, 0.2)",
|
|
97
|
+
borderRadius: "6px",
|
|
98
|
+
padding: "0.2em 0.4em"
|
|
99
|
+
},
|
|
100
|
+
a: {
|
|
101
|
+
color: "#0969da",
|
|
102
|
+
textDecoration: "none"
|
|
103
|
+
},
|
|
104
|
+
hr: {
|
|
105
|
+
border: 0,
|
|
106
|
+
borderTop: "1px solid #d0d7de",
|
|
107
|
+
margin: "24px 0"
|
|
108
|
+
},
|
|
109
|
+
img: {
|
|
110
|
+
maxWidth: "100%"
|
|
111
|
+
},
|
|
112
|
+
kbd: {
|
|
113
|
+
display: "inline-block",
|
|
114
|
+
padding: "3px 5px",
|
|
115
|
+
fontSize: "11px",
|
|
116
|
+
lineHeight: "10px",
|
|
117
|
+
color: "#1f2328",
|
|
118
|
+
verticalAlign: "middle",
|
|
119
|
+
backgroundColor: "#f6f8fa",
|
|
120
|
+
border: "1px solid #d0d7de",
|
|
121
|
+
borderRadius: "6px",
|
|
122
|
+
boxShadow: "inset 0 -1px 0 #d0d7de"
|
|
123
|
+
},
|
|
124
|
+
del: {
|
|
125
|
+
color: "#656d76"
|
|
126
|
+
}
|
|
127
|
+
}, D = "mjx-", U = /* @__PURE__ */ new Set(["math"]);
|
|
128
|
+
function P(e) {
|
|
129
|
+
if (!e) return {};
|
|
130
|
+
const n = { ...e };
|
|
131
|
+
return "className" in n && (n.class = n.className, delete n.className), "htmlFor" in n && (n.for = n.htmlFor, delete n.htmlFor), n;
|
|
132
|
+
}
|
|
133
|
+
function N(e, n) {
|
|
134
|
+
return n ? Array.isArray(n) ? [e ?? {}, ...n] : [e ?? {}, n] : e;
|
|
135
|
+
}
|
|
136
|
+
function c(e) {
|
|
137
|
+
return (n) => {
|
|
138
|
+
const { children: r, style: t, ...a } = n, i = { ...a };
|
|
139
|
+
delete i.node;
|
|
140
|
+
const d = r ?? void 0, s = { ...i, style: N(M[e], t) };
|
|
141
|
+
return d === void 0 ? h(e, s) : h(e, s, d);
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function V() {
|
|
145
|
+
return (e) => {
|
|
146
|
+
const {
|
|
147
|
+
children: n,
|
|
148
|
+
style: r,
|
|
149
|
+
class: t,
|
|
150
|
+
className: a,
|
|
151
|
+
...i
|
|
152
|
+
} = e, d = { ...i };
|
|
153
|
+
delete d.node;
|
|
154
|
+
const s = t ?? a, f = typeof s == "string" ? s : void 0, p = !!(f && f.includes("language-")), u = M.code ?? {}, o = p ? {
|
|
155
|
+
fontFamily: u.fontFamily,
|
|
156
|
+
fontSize: u.fontSize,
|
|
157
|
+
padding: 0,
|
|
158
|
+
backgroundColor: "transparent"
|
|
159
|
+
} : u, l = n ?? void 0, m = {
|
|
160
|
+
...d,
|
|
161
|
+
class: s,
|
|
162
|
+
style: N(o, r)
|
|
163
|
+
};
|
|
164
|
+
return l === void 0 ? h("code", m) : h("code", m, l);
|
|
165
|
+
};
|
|
166
|
+
}
|
|
167
|
+
function _() {
|
|
168
|
+
return {
|
|
169
|
+
h1: c("h1"),
|
|
170
|
+
h2: c("h2"),
|
|
171
|
+
h3: c("h3"),
|
|
172
|
+
h4: c("h4"),
|
|
173
|
+
h5: c("h5"),
|
|
174
|
+
h6: c("h6"),
|
|
175
|
+
p: c("p"),
|
|
176
|
+
blockquote: c("blockquote"),
|
|
177
|
+
ul: c("ul"),
|
|
178
|
+
ol: c("ol"),
|
|
179
|
+
li: c("li"),
|
|
180
|
+
table: c("table"),
|
|
181
|
+
th: c("th"),
|
|
182
|
+
td: c("td"),
|
|
183
|
+
pre: c("pre"),
|
|
184
|
+
code: V(),
|
|
185
|
+
a: c("a"),
|
|
186
|
+
hr: c("hr"),
|
|
187
|
+
img: c("img"),
|
|
188
|
+
kbd: c("kbd"),
|
|
189
|
+
del: c("del")
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
const K = _();
|
|
193
|
+
function Q(e) {
|
|
194
|
+
const n = { ...e };
|
|
195
|
+
for (const r of Object.keys(n))
|
|
196
|
+
(r.startsWith(D) || U.has(r)) && delete n[r];
|
|
197
|
+
return n;
|
|
198
|
+
}
|
|
199
|
+
function Y(e) {
|
|
200
|
+
const n = {
|
|
201
|
+
...K,
|
|
202
|
+
...(e == null ? void 0 : e.components) ?? {}
|
|
203
|
+
};
|
|
204
|
+
return e != null && e.codeRenderer && (n.code = e.codeRenderer), Q(n);
|
|
205
|
+
}
|
|
206
|
+
const S = (e, n, r) => {
|
|
207
|
+
const t = P(n), { children: a, ...i } = t, d = r == null ? i : { ...i, key: r };
|
|
208
|
+
if (typeof e == "string") {
|
|
209
|
+
const f = { ...d };
|
|
210
|
+
return delete f.node, a == null ? h(e, f) : h(e, f, a);
|
|
211
|
+
}
|
|
212
|
+
if (a == null)
|
|
213
|
+
return h(e, d);
|
|
214
|
+
const s = { ...d, children: a };
|
|
215
|
+
return h(e, s, a);
|
|
216
|
+
};
|
|
217
|
+
function w(e, n) {
|
|
218
|
+
const r = [];
|
|
219
|
+
for (let t = 0; t < e.children.length; t += 1) {
|
|
220
|
+
const a = q(e.children[t], n, t);
|
|
221
|
+
a != null && r.push(a);
|
|
222
|
+
}
|
|
223
|
+
return r;
|
|
224
|
+
}
|
|
225
|
+
function q(e, n, r) {
|
|
226
|
+
switch (e.type) {
|
|
227
|
+
case "root": {
|
|
228
|
+
const t = w(e, n);
|
|
229
|
+
return t.length ? S(W, { children: t }, void 0) : null;
|
|
230
|
+
}
|
|
231
|
+
case "element": {
|
|
232
|
+
const t = e, a = n[t.tagName] ?? t.tagName, i = P(
|
|
233
|
+
t.properties ?? {}
|
|
234
|
+
);
|
|
235
|
+
i.node = t;
|
|
236
|
+
const d = t.tagName === "template" && t.content ? t.content : t, s = w(d, n);
|
|
237
|
+
return s.length && (i.children = s), S(a, i, r == null ? void 0 : r.toString());
|
|
238
|
+
}
|
|
239
|
+
case "text":
|
|
240
|
+
return e.value;
|
|
241
|
+
case "comment":
|
|
242
|
+
case "doctype":
|
|
243
|
+
default:
|
|
244
|
+
return null;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
function z(e, n) {
|
|
248
|
+
const r = Y(n);
|
|
249
|
+
return q(e, r);
|
|
250
|
+
}
|
|
251
|
+
function A(e) {
|
|
252
|
+
if (e instanceof Error) return e;
|
|
253
|
+
if (typeof e == "string") return new Error(e);
|
|
254
|
+
try {
|
|
255
|
+
return new Error(JSON.stringify(e));
|
|
256
|
+
} catch {
|
|
257
|
+
return new Error("Unknown error");
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
function B(e, n, r) {
|
|
261
|
+
const t = O(null), a = k(!1), i = k(null);
|
|
262
|
+
let d = null, s = 0;
|
|
263
|
+
const f = async (u, o) => {
|
|
264
|
+
const l = ++s;
|
|
265
|
+
a.value = !0, i.value = null;
|
|
266
|
+
try {
|
|
267
|
+
const m = await n(u, o);
|
|
268
|
+
l === s && (t.value = m);
|
|
269
|
+
} catch (m) {
|
|
270
|
+
l === s && (i.value = A(m));
|
|
271
|
+
} finally {
|
|
272
|
+
l === s && (a.value = !1);
|
|
273
|
+
}
|
|
274
|
+
}, p = (u, o) => {
|
|
275
|
+
const l = (o == null ? void 0 : o.dynamic) ?? !1, m = (o == null ? void 0 : o.debounceMs) ?? 250;
|
|
276
|
+
if (d != null && (globalThis.clearTimeout(d), d = null), l) {
|
|
277
|
+
d = globalThis.setTimeout(() => {
|
|
278
|
+
f(u, o);
|
|
279
|
+
}, m);
|
|
280
|
+
return;
|
|
281
|
+
}
|
|
282
|
+
f(u, o);
|
|
283
|
+
};
|
|
284
|
+
return v(
|
|
285
|
+
() => [x(e), r ? x(r) : void 0],
|
|
286
|
+
([u, o]) => {
|
|
287
|
+
p(u ?? "", o);
|
|
288
|
+
},
|
|
289
|
+
{ immediate: !0, deep: !0 }
|
|
290
|
+
), C(() => {
|
|
291
|
+
d != null && globalThis.clearTimeout(d);
|
|
292
|
+
}), {
|
|
293
|
+
content: t,
|
|
294
|
+
loading: a,
|
|
295
|
+
error: i
|
|
296
|
+
};
|
|
297
|
+
}
|
|
298
|
+
function Z(e, n, r) {
|
|
299
|
+
const t = X(n ?? {});
|
|
300
|
+
return B(
|
|
301
|
+
e,
|
|
302
|
+
async (a, i) => {
|
|
303
|
+
const d = await t.parseToHAST(a);
|
|
304
|
+
return z(d, i);
|
|
305
|
+
},
|
|
306
|
+
r
|
|
307
|
+
);
|
|
308
|
+
}
|
|
309
|
+
function $(e, n, r) {
|
|
310
|
+
return B(
|
|
311
|
+
e,
|
|
312
|
+
async (t, a) => {
|
|
313
|
+
const i = await n.parseToHAST(t);
|
|
314
|
+
return z(i, a);
|
|
315
|
+
},
|
|
316
|
+
r
|
|
317
|
+
);
|
|
318
|
+
}
|
|
319
|
+
const ee = {
|
|
320
|
+
display: "inline-flex",
|
|
321
|
+
alignItems: "center",
|
|
322
|
+
gap: "8px",
|
|
323
|
+
color: "#57606a",
|
|
324
|
+
fontSize: "14px"
|
|
325
|
+
}, ne = {
|
|
326
|
+
padding: "12px 16px",
|
|
327
|
+
borderRadius: "8px",
|
|
328
|
+
backgroundColor: "#ffebe9",
|
|
329
|
+
color: "#cf222e",
|
|
330
|
+
border: "1px solid #ff8182",
|
|
331
|
+
fontSize: "14px"
|
|
332
|
+
}, oe = /* @__PURE__ */ T({
|
|
333
|
+
name: "MarkdownRenderer",
|
|
334
|
+
inheritAttrs: !1,
|
|
335
|
+
props: {
|
|
336
|
+
markdown: {
|
|
337
|
+
type: String,
|
|
338
|
+
required: !0
|
|
339
|
+
},
|
|
340
|
+
parserOptions: {
|
|
341
|
+
type: Object,
|
|
342
|
+
required: !1,
|
|
343
|
+
default: void 0
|
|
344
|
+
},
|
|
345
|
+
components: {
|
|
346
|
+
type: Object,
|
|
347
|
+
required: !1,
|
|
348
|
+
default: void 0
|
|
349
|
+
},
|
|
350
|
+
codeRenderer: {
|
|
351
|
+
type: [Object, Function, String],
|
|
352
|
+
required: !1,
|
|
353
|
+
default: void 0
|
|
354
|
+
},
|
|
355
|
+
dynamic: {
|
|
356
|
+
type: Boolean,
|
|
357
|
+
default: !1
|
|
358
|
+
},
|
|
359
|
+
debounceMs: {
|
|
360
|
+
type: Number,
|
|
361
|
+
default: 250
|
|
362
|
+
}
|
|
363
|
+
},
|
|
364
|
+
setup(e) {
|
|
365
|
+
const n = F(), r = E(e, "markdown"), t = L(R, null), a = k(null), i = y(() => {
|
|
366
|
+
const o = {
|
|
367
|
+
dynamic: e.dynamic,
|
|
368
|
+
debounceMs: e.debounceMs
|
|
369
|
+
};
|
|
370
|
+
if (t != null && t.forceRenderOptions.value) {
|
|
371
|
+
const l = t.renderOptions.value;
|
|
372
|
+
return l != null && l.components && (o.components = l.components), l != null && l.codeRenderer && (o.codeRenderer = l.codeRenderer), o.dynamic = (l == null ? void 0 : l.dynamic) ?? !1, o.debounceMs = (l == null ? void 0 : l.debounceMs) ?? 250, o;
|
|
373
|
+
}
|
|
374
|
+
return e.components && (o.components = e.components), e.codeRenderer && (o.codeRenderer = e.codeRenderer), o;
|
|
375
|
+
}), d = t ? $(r, t.pool, i) : Z(r, e.parserOptions, i);
|
|
376
|
+
j((o) => (a.value = A(o), !1)), v(r, () => {
|
|
377
|
+
a.value = null;
|
|
378
|
+
});
|
|
379
|
+
const s = y(() => [I, n.style]), f = y(() => {
|
|
380
|
+
const l = {
|
|
381
|
+
...n
|
|
382
|
+
};
|
|
383
|
+
return delete l.style, l;
|
|
384
|
+
}), p = () => g("div", {
|
|
385
|
+
style: ee
|
|
386
|
+
}, [g("svg", {
|
|
387
|
+
width: "16",
|
|
388
|
+
height: "16",
|
|
389
|
+
viewBox: "0 0 50 50",
|
|
390
|
+
"aria-hidden": "true"
|
|
391
|
+
}, [g("circle", {
|
|
392
|
+
cx: "25",
|
|
393
|
+
cy: "25",
|
|
394
|
+
r: "20",
|
|
395
|
+
fill: "none",
|
|
396
|
+
stroke: "#57606a",
|
|
397
|
+
"stroke-width": "4",
|
|
398
|
+
"stroke-linecap": "round",
|
|
399
|
+
"stroke-dasharray": "31.4 31.4"
|
|
400
|
+
}, [g("animateTransform", {
|
|
401
|
+
attributeName: "transform",
|
|
402
|
+
type: "rotate",
|
|
403
|
+
from: "0 25 25",
|
|
404
|
+
to: "360 25 25",
|
|
405
|
+
dur: "1s",
|
|
406
|
+
repeatCount: "indefinite"
|
|
407
|
+
}, null)])]), g("span", null, [b("Rendering markdown...")])]), u = (o) => g("div", {
|
|
408
|
+
style: ne
|
|
409
|
+
}, [g("strong", null, [b("Markdown render error:")]), b(" "), o.message]);
|
|
410
|
+
return () => {
|
|
411
|
+
const o = a.value ?? d.error.value, l = d.content.value, m = d.loading.value && !l && !o;
|
|
412
|
+
return g("div", H(f.value, {
|
|
413
|
+
style: s.value
|
|
414
|
+
}), [o ? u(o) : m ? p() : l]);
|
|
415
|
+
};
|
|
416
|
+
}
|
|
417
|
+
}), de = /* @__PURE__ */ T({
|
|
418
|
+
name: "MarkdownWorkerPoll",
|
|
419
|
+
props: {
|
|
420
|
+
parserOptions: {
|
|
421
|
+
type: Object,
|
|
422
|
+
required: !1,
|
|
423
|
+
default: void 0
|
|
424
|
+
},
|
|
425
|
+
workerCount: {
|
|
426
|
+
type: Number,
|
|
427
|
+
required: !0
|
|
428
|
+
},
|
|
429
|
+
customTags: {
|
|
430
|
+
type: Array,
|
|
431
|
+
required: !1,
|
|
432
|
+
default: void 0
|
|
433
|
+
},
|
|
434
|
+
extendedGrammar: {
|
|
435
|
+
type: Array,
|
|
436
|
+
required: !1,
|
|
437
|
+
default: void 0
|
|
438
|
+
},
|
|
439
|
+
remarkPlugins: {
|
|
440
|
+
type: Array,
|
|
441
|
+
required: !1,
|
|
442
|
+
default: void 0
|
|
443
|
+
},
|
|
444
|
+
rehypePlugins: {
|
|
445
|
+
type: Array,
|
|
446
|
+
required: !1,
|
|
447
|
+
default: void 0
|
|
448
|
+
},
|
|
449
|
+
mathJaxConfig: {
|
|
450
|
+
type: Object,
|
|
451
|
+
required: !1,
|
|
452
|
+
default: void 0
|
|
453
|
+
},
|
|
454
|
+
supportsLaTeX: {
|
|
455
|
+
type: Boolean,
|
|
456
|
+
required: !1,
|
|
457
|
+
default: void 0
|
|
458
|
+
},
|
|
459
|
+
components: {
|
|
460
|
+
type: Object,
|
|
461
|
+
required: !1,
|
|
462
|
+
default: void 0
|
|
463
|
+
},
|
|
464
|
+
codeRenderer: {
|
|
465
|
+
type: [Object, Function, String],
|
|
466
|
+
required: !1,
|
|
467
|
+
default: void 0
|
|
468
|
+
},
|
|
469
|
+
dynamic: {
|
|
470
|
+
type: Boolean,
|
|
471
|
+
required: !1,
|
|
472
|
+
default: void 0
|
|
473
|
+
},
|
|
474
|
+
debounceMs: {
|
|
475
|
+
type: Number,
|
|
476
|
+
required: !1,
|
|
477
|
+
default: void 0
|
|
478
|
+
}
|
|
479
|
+
},
|
|
480
|
+
setup(e, {
|
|
481
|
+
slots: n
|
|
482
|
+
}) {
|
|
483
|
+
const r = {
|
|
484
|
+
...e.parserOptions ?? {}
|
|
485
|
+
};
|
|
486
|
+
e.workerCount != null && (r.workerCount = e.workerCount), e.customTags && (r.customTags = e.customTags), e.extendedGrammar && (r.extendedGrammar = e.extendedGrammar), e.remarkPlugins && (r.remarkPlugins = e.remarkPlugins), e.rehypePlugins && (r.rehypePlugins = e.rehypePlugins), e.mathJaxConfig && (r.mathJaxConfig = e.mathJaxConfig), e.supportsLaTeX != null && (r.supportsLaTeX = e.supportsLaTeX);
|
|
487
|
+
const t = G(r), a = y(() => {
|
|
488
|
+
if (e.components == null && e.codeRenderer == null && e.dynamic == null && e.debounceMs == null)
|
|
489
|
+
return;
|
|
490
|
+
const d = {
|
|
491
|
+
dynamic: e.dynamic ?? !1,
|
|
492
|
+
debounceMs: e.debounceMs ?? 250
|
|
493
|
+
};
|
|
494
|
+
return e.components && (d.components = e.components), e.codeRenderer && (d.codeRenderer = e.codeRenderer), d;
|
|
495
|
+
}), i = y(() => a.value !== void 0);
|
|
496
|
+
return J(R, {
|
|
497
|
+
pool: t,
|
|
498
|
+
renderOptions: a,
|
|
499
|
+
forceRenderOptions: i
|
|
500
|
+
}), C(() => {
|
|
501
|
+
t.destroy();
|
|
502
|
+
}), () => {
|
|
503
|
+
var d;
|
|
504
|
+
return (d = n.default) == null ? void 0 : d.call(n);
|
|
505
|
+
};
|
|
506
|
+
}
|
|
507
|
+
});
|
|
508
|
+
export {
|
|
509
|
+
oe as MarkdownRenderer,
|
|
510
|
+
de as MarkdownWorkerPoll,
|
|
511
|
+
Z as useMarkdownParser,
|
|
512
|
+
$ as useMarkdownWorkerPool
|
|
513
|
+
};
|
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import type { Component, FunctionalComponent, Ref } from 'vue';
|
|
2
|
+
import type { ParserOptions } from '@markdown-next/parser';
|
|
3
|
+
export type MarkdownComponent = Component | FunctionalComponent | string;
|
|
4
|
+
export type MarkdownComponents = Record<string, MarkdownComponent>;
|
|
5
|
+
export interface MarkdownRenderOptions {
|
|
6
|
+
components?: MarkdownComponents;
|
|
7
|
+
codeRenderer?: MarkdownComponent;
|
|
8
|
+
dynamic?: boolean;
|
|
9
|
+
debounceMs?: number;
|
|
10
|
+
}
|
|
11
|
+
export interface MarkdownRendererProps extends MarkdownRenderOptions {
|
|
12
|
+
markdown: string;
|
|
13
|
+
parserOptions?: ParserOptions;
|
|
14
|
+
}
|
|
15
|
+
export interface MarkdownWorkerPollProps extends MarkdownRenderOptions {
|
|
16
|
+
parserOptions?: ParserOptions;
|
|
17
|
+
workerCount?: number;
|
|
18
|
+
customTags?: string[];
|
|
19
|
+
extendedGrammar?: ParserOptions['extendedGrammar'];
|
|
20
|
+
remarkPlugins?: ParserOptions['remarkPlugins'];
|
|
21
|
+
rehypePlugins?: ParserOptions['rehypePlugins'];
|
|
22
|
+
mathJaxConfig?: ParserOptions['mathJaxConfig'];
|
|
23
|
+
supportsLaTeX?: ParserOptions['supportsLaTeX'];
|
|
24
|
+
}
|
|
25
|
+
export interface UseMarkdownResult<T> {
|
|
26
|
+
content: T;
|
|
27
|
+
loading: Ref<boolean>;
|
|
28
|
+
error: Ref<Error | null>;
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function toError(value: unknown): Error;
|
package/package.json
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@markdown-next/vue",
|
|
3
|
+
"version": "0.0.1-alpha",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"description": "Vue renderer for markdown-next",
|
|
6
|
+
"module": "dist/index.mjs",
|
|
7
|
+
"types": "dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./dist/index.d.ts",
|
|
11
|
+
"import": "./dist/index.mjs"
|
|
12
|
+
}
|
|
13
|
+
},
|
|
14
|
+
"files": [
|
|
15
|
+
"./dist",
|
|
16
|
+
"./package.json",
|
|
17
|
+
"./README.md"
|
|
18
|
+
],
|
|
19
|
+
"keywords": [
|
|
20
|
+
"markdown",
|
|
21
|
+
"vue",
|
|
22
|
+
"renderer",
|
|
23
|
+
"worker"
|
|
24
|
+
],
|
|
25
|
+
"author": "",
|
|
26
|
+
"license": "MIT",
|
|
27
|
+
"repository": {
|
|
28
|
+
"type": "git",
|
|
29
|
+
"url": "https://github.com/yourusername/vue-markdown-next.git",
|
|
30
|
+
"directory": "packages/vue"
|
|
31
|
+
},
|
|
32
|
+
"bugs": {
|
|
33
|
+
"url": "https://github.com/yourusername/vue-markdown-next/issues"
|
|
34
|
+
},
|
|
35
|
+
"engines": {
|
|
36
|
+
"node": ">=16.0.0"
|
|
37
|
+
},
|
|
38
|
+
"dependencies": {
|
|
39
|
+
"hast-util-to-jsx-runtime": "^2.3.0",
|
|
40
|
+
"@markdown-next/parser": "0.0.1-alpha"
|
|
41
|
+
},
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"@types/hast": "^3.0.4",
|
|
44
|
+
"@types/node": "^25.0.3",
|
|
45
|
+
"@vitejs/plugin-vue-jsx": "^4.2.0",
|
|
46
|
+
"vite": "^5.4.10",
|
|
47
|
+
"vitest": "^4.0.16",
|
|
48
|
+
"vue": "^3.5.0"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"vue": ">=3.2.0"
|
|
52
|
+
},
|
|
53
|
+
"sideEffects": false,
|
|
54
|
+
"scripts": {
|
|
55
|
+
"dev": "vite",
|
|
56
|
+
"build": "vite build && tsc -p tsconfig.build.json",
|
|
57
|
+
"typecheck": "tsc -b",
|
|
58
|
+
"lint": "eslint src --ext .ts,.tsx",
|
|
59
|
+
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
60
|
+
"test": "vitest"
|
|
61
|
+
}
|
|
62
|
+
}
|