UNPKG

mdast-util-to-vnode

Version:

mdast utility to get the vue vnode

236 lines (235 loc) 4.47 kB
import { h as t, Comment as O, Text as j } from "vue"; function p(r) { return Array.isArray(r); } function C(r) { return typeof r == "object" && r !== null; } function y(r) { return typeof r == "function"; } function s(r) { return C(r) && !p(r) && !y(r); } function i(r, ...l) { if (!s(r)) return r; const c = l.filter((a) => s(a)); if (!c.length) return r; const e = c.shift(); for (const a in e) s(e[a]) ? (Object.prototype.hasOwnProperty.call(r, a) || Object.assign(r, { [a]: {} }), i(r[a], e[a])) : Object.assign(r, { [a]: e[a] }); return i(r, ...c); } function n(r, l) { return l.reduce((c, e) => (c[e] = r[e], c), {}); } function N(r, l = {}) { return v(r, l, { index: 0, parent: null }); } function v(r, l = {}, c) { var f, m, h, b, g; let e = (f = l.components) == null ? void 0 : f[r.type], a = {}; switch (y(e) && (e = e(r)), p(e) && (a = e[1] ?? {}, e = e[0]), r.type) { case "blockquote": return t( e ?? "blockquote", a, u(r, l) ); case "break": return t( e ?? "br", a ); case "code": return e ? t( e, i(n(r, ["lang", "meta", "value"]), a) ) : t( "pre", { "data-lang": r.lang, "data-meta": r.meta }, t("code", r.value) ); case "delete": return t( e ?? "s", a, u(r, l) ); case "emphasis": return t( e ?? "em", a, u(r, l) ); case "heading": return e ? t( e, i(n(r, ["depth"]), a) ) : t( `h${r.depth}`, u(r, l) ); case "html": return e ? t( e, i(n(r, ["value"]), a) ) : t( "div", { innerHTML: r.value } ); case "image": return e ? t( e, i(n(r, ["url", "alt", "title"]), a) ) : t( "img", { src: r.url, alt: r.alt, title: r.title } ); case "inlineCode": return e ? t( e, i(n(r, ["value"]), a) ) : t( "code", r.value ); case "link": return e ? t( e, i( { target: "_blank" }, n(r, ["url", "title"]), a ), u(r, l) ) : t( "a", { href: r.url, target: "_blank" }, u(r, l) ); case "list": return e ? t( e, i(n(r, ["ordered", "spread", "start"]), a), u(r, l) ) : t( r.ordered ? "ol" : "ul", u(r, l) ); case "listItem": return e ? t( e, i(n(r, ["checked", "spread"]), a), u(r, l) ) : t( "li", u(r, l) ); case "paragraph": return t( e ?? "p", a, u(r, l) ); case "root": return t( e ?? "div", a, u(r, l) ); case "strong": return t( e ?? "strong", a, u(r, l) ); case "table": return t( e ?? "table", a, u(r, l) ); case "tableRow": return e ? t( e, i(a, { index: c.index, align: ((m = c.parent.align) == null ? void 0 : m[c.index]) ?? "left" }), u(r, l) ) : t("tr", { align: ((h = c.parent.align) == null ? void 0 : h[c.index]) ?? "left" }, u(r, l)); case "tableCell": { const k = ((g = (b = c.parent.position) == null ? void 0 : b.start) == null ? void 0 : g.offset) === 0; return t( e ?? (k ? "th" : "td"), a, u(r, l) ); } case "text": return t( j, r.value ); case "thematicBreak": return t( e ?? "hr", a ); case "yaml": return e ? t( e, i( { lang: "yaml", value: r.value }, a ) ) : t( "pre", { "data-lang": "yaml" }, t("code", r.value) ); default: return e ? t( e, a ) : t(O, JSON.stringify(r)); } } function u(r, l = {}) { var c; return ((c = r.children) == null ? void 0 : c.map((e, a) => v(e, l, { index: a, parent: r }))) ?? []; } export { v as createVNode, N as toVNode };