UNPKG

vue-markdown-wasm

Version:
174 lines (172 loc) 4.66 kB
/** * vue-markdown-wasm * * @description markdown-wasm for vue 2 & 3 * @author Logue <logue@hotmail.co.jp> * @copyright 2022-2025 By Masashi Yoshikawa All rights reserved. * @license MIT * @version 0.5.2 * @see {@link https://github.com/logue/vue-markdown-wasm} */ import { ParseFlags as u, ready as m, parse as c } from "@logue/markdown-wasm"; import { isVue2 as f, h as d, defineComponent as b, ref as i, watch as h, nextTick as p, onMounted as g } from "vue-demi"; const F = { version: "0.5.2", date: "2025-07-12T05:52:57.079Z" }, w = (e) => e ? Object.entries(e).reduce((n, [a, l]) => (a = a.charAt(0).toUpperCase() + a.slice(1), a = `on${a}`, { ...n, [a]: l }), {}) : {}; function y(e, n = {}, a) { if (f) return d(e, n, a); const { props: l, domProps: r, on: t, ...s } = n, o = t != null ? w(t) : {}; return d( e, { ...s, ...l, ...r, ...o }, a ); } var B = b({ /** Component Name */ name: "VueMarkdown", /** Model Definition */ model: { prop: "modelValue" }, /** Props Definition */ props: { /** Model value */ modelValue: { type: String, default: "" }, /** * Using tag */ tag: { type: String, default: "article" }, /** Customize parsing */ parseFlags: { type: Number, default: u.DEFAULT }, /** Select output format. */ format: { type: String, default: "xhtml" }, /** * bytes=true causes parse() to return the result as a Uint8Array instead of a string. * * The returned Uint8Array is only valid until the next call to parse(). * If you need to keep the returned data around, call Uint8Array.slice() to make a copy, * as each call to parse() uses the same underlying memory. * * This only provides a performance benefit when you never need to convert the output * to a string. In most cases you're better off leaving this unset or false. */ bytes: { type: Boolean, default: !1 }, /** Allow "javascript:" in links */ allowJsUri: { type: Boolean, default: !1 }, /** * Optional callback which if provided is called for each code block. * langname holds the "language tag", if any, of the block. * * The returned value is inserted into the resulting HTML verbatim, without HTML escaping. * Thus, you should take care of properly escaping any special HTML characters. * * If the function returns null or undefined, or an exception occurs, the body will be * included as-is after going through HTML escaping. * * Note that use of this callback has an adverse impact on performance as it casues * calls and data to be bridged between WASM and JS on every invocation. */ onCodeBlock: { type: Function }, /** Enable Debug log. default is false */ debug: { type: Boolean, default: !1 }, /** Output special characters as entity reference characters */ verbatimEntities: { type: Boolean, default: !0 }, /** Disable anchor tag in headlines. Defaults to `false` */ disableHeadlineAnchors: { type: Boolean, default: !1 } }, /** Emits */ emits: { render: (e) => !0 }, /** * Setup * * @param props - Props * @param context - Context */ setup(e, n) { const a = i(), l = i(""); h( () => e, async (t) => { l.value = r(t.modelValue, { parseFlags: t.parseFlags, xhtml: t.format === "xhtml", bytes: e.bytes, allowJSURIs: t.allowJsUri, onCodeBlock: t.onCodeBlock, debug: t.debug, verbatimEntities: t.verbatimEntities, disableHeadlineAnchors: t.disableHeadlineAnchors }), await p(); }, { deep: !0 } ), g(async () => { await m(), l.value = r(e.modelValue, { parseFlags: e.parseFlags, xhtml: e.format == "xhtml", bytes: e.bytes, allowJSURIs: e.allowJsUri, onCodeBlock: e.onCodeBlock, debug: e.debug, verbatimEntities: e.verbatimEntities, disableHeadlineAnchors: e.disableHeadlineAnchors }); }); const r = (t, s) => { const o = c(t, s); return n.emit("render", o), o; }; return n.expose({ render: r }), { placeholder: a, html: l }; }, render() { return y(this.$props.tag, { ref: "placeholder", class: "vue-markdown", innerHTML: this.html }); } }); const A = (e) => e.component("VueMarkdown", B); export { F as Meta, B as default, A as install };