vue-files-preview-inno
Version:
A tool for previewing files such as doc, excel, pdf, image, markdown, txt, audio, and video and so on.
114 lines (113 loc) • 4.04 kB
JavaScript
import * as m from "./common/utils.mjs";
import { isString as c, assign as a } from "./common/utils.mjs";
import * as p from "./helpers/index.mjs";
import d from "./renderer.mjs";
import w from "./parser_core.mjs";
import y from "./parser_block.mjs";
import k from "./parser_inline.mjs";
import g from "../../linkify-it/index.mjs";
import s from "../../mdurl/lib/decode.mjs";
import b from "../../mdurl/lib/encode.mjs";
import f from "../../mdurl/lib/format.mjs";
import u from "../../mdurl/lib/parse.mjs";
import l from "../../punycode.js/punycode.es6.mjs";
import O from "./presets/default.mjs";
import E from "./presets/zero.mjs";
import I from "./presets/commonmark.mjs";
const A = {
default: O,
zero: E,
commonmark: I
}, _ = /^(vbscript|javascript|file|data):/, x = /^data:image\/(gif|png|jpeg|webp);/;
function L(t) {
const r = t.trim().toLowerCase();
return _.test(r) ? x.test(r) : !0;
}
const h = ["http:", "https:", "mailto:"];
function z(t) {
const r = u(t, !0);
if (r.hostname && (!r.protocol || h.indexOf(r.protocol) >= 0))
try {
r.hostname = l.toASCII(r.hostname);
} catch {
}
return b(f(r));
}
function R(t) {
const r = u(t, !0);
if (r.hostname && (!r.protocol || h.indexOf(r.protocol) >= 0))
try {
r.hostname = l.toUnicode(r.hostname);
} catch {
}
return s(f(r), s.defaultChars + "%");
}
function n(t, r) {
if (!(this instanceof n))
return new n(t, r);
r || c(t) || (r = t || {}, t = "default"), this.inline = new k(), this.block = new y(), this.core = new w(), this.renderer = new d(), this.linkify = new g(), this.validateLink = L, this.normalizeLink = z, this.normalizeLinkText = R, this.utils = m, this.helpers = a({}, p), this.options = {}, this.configure(t), r && this.set(r);
}
n.prototype.set = function(t) {
return a(this.options, t), this;
};
n.prototype.configure = function(t) {
const r = this;
if (c(t)) {
const o = t;
if (t = A[o], !t)
throw new Error('Wrong `markdown-it` preset "' + o + '", check name');
}
if (!t)
throw new Error("Wrong `markdown-it` preset, can't be empty");
return t.options && r.set(t.options), t.components && Object.keys(t.components).forEach(function(o) {
t.components[o].rules && r[o].ruler.enableOnly(t.components[o].rules), t.components[o].rules2 && r[o].ruler2.enableOnly(t.components[o].rules2);
}), this;
};
n.prototype.enable = function(t, r) {
let o = [];
Array.isArray(t) || (t = [t]), ["core", "block", "inline"].forEach(function(e) {
o = o.concat(this[e].ruler.enable(t, !0));
}, this), o = o.concat(this.inline.ruler2.enable(t, !0));
const i = t.filter(function(e) {
return o.indexOf(e) < 0;
});
if (i.length && !r)
throw new Error("MarkdownIt. Failed to enable unknown rule(s): " + i);
return this;
};
n.prototype.disable = function(t, r) {
let o = [];
Array.isArray(t) || (t = [t]), ["core", "block", "inline"].forEach(function(e) {
o = o.concat(this[e].ruler.disable(t, !0));
}, this), o = o.concat(this.inline.ruler2.disable(t, !0));
const i = t.filter(function(e) {
return o.indexOf(e) < 0;
});
if (i.length && !r)
throw new Error("MarkdownIt. Failed to disable unknown rule(s): " + i);
return this;
};
n.prototype.use = function(t) {
const r = [this].concat(Array.prototype.slice.call(arguments, 1));
return t.apply(t, r), this;
};
n.prototype.parse = function(t, r) {
if (typeof t != "string")
throw new Error("Input data should be a String");
const o = new this.core.State(t, this, r);
return this.core.process(o), o.tokens;
};
n.prototype.render = function(t, r) {
return r = r || {}, this.renderer.render(this.parse(t, r), this.options, r);
};
n.prototype.parseInline = function(t, r) {
const o = new this.core.State(t, this, r);
return o.inlineMode = !0, this.core.process(o), o.tokens;
};
n.prototype.renderInline = function(t, r) {
return r = r || {}, this.renderer.render(this.parseInline(t, r), this.options, r);
};
export {
n as default
};
//# sourceMappingURL=index.mjs.map