@felixrydberg/discord-markdown
Version:
A markdown parser that matches Discords markdown spec.
1,725 lines (1,721 loc) • 1.43 MB
JavaScript
const ql = (n, e) => {
let t = "v";
e === "__lib_version__" && (t = "");
const a = `${t}${e}`;
if (typeof globalThis < "u") {
var r;
globalThis.__perseus_debug__ = (r = globalThis.__perseus_debug__) != null ? r : {};
const i = globalThis.__perseus_debug__[n];
if (i) {
if (i !== a) {
const s = Array.isArray(i) ? i : [i];
s.push(a), globalThis.__perseus_debug__[n] = s, console.warn(`Multiple versions of ${n} loaded on this page: ${s.sort().join(", ")}`);
}
} else
globalThis.__perseus_debug__[n] = a;
} else
console.warn(`globalThis not found found (${a})`);
}, S_ = "@khanacademy/perseus-core", g_ = "1.2.0";
ql(S_, g_);
const T_ = "@khanacademy/simple-markdown", b_ = "0.10.3";
ql(T_, b_);
var R_ = /\r\n?/g, f_ = /\t/g, C_ = /\f/g, Hl = function(e) {
return e.replace(R_, `
`).replace(C_, "").replace(f_, " ");
}, Vl = function(e, t) {
var a = e || {};
if (t != null)
for (var r in t)
Object.prototype.hasOwnProperty.call(t, r) && (a[r] = t[r]);
return a;
}, zl = function(e, t) {
var a = Object.keys(e).filter(function(o) {
var l = e[o];
if (l == null || l.match == null)
return !1;
var c = l.order;
return (typeof c != "number" || !isFinite(c)) && typeof console < "u" && console.warn("simple-markdown: Invalid order for rule `" + o + "`: " + String(c)), !0;
});
a.sort(function(o, l) {
var c = e[o], _ = e[l], d = c.order, u = _.order;
if (d !== u)
return d - u;
var p = c.quality ? 0 : 1, E = _.quality ? 0 : 1;
return p !== E ? p - E : o < l ? -1 : o > l ? 1 : 0;
});
var r, i = function o(l, c) {
var _ = [];
for (c = c || r, r = c; l; ) {
var d = null, u = null, p = null, E = NaN, S = 0, g = a[0], T = e[g];
do {
var R = T.order, C = c.prevCapture == null ? "" : c.prevCapture[0], N = T.match(l, c, C);
if (N) {
var O = T.quality ? T.quality(N, c, C) : 0;
O <= E || (d = g, u = T, p = N, E = O);
}
S++, g = a[S], T = e[g];
} while (
// keep looping while we're still within the ruleList
T && // if we don't have a match yet, continue
(!p || // or if we have a match, but the next rule is
// at the same order, and has a quality measurement
// functions, then this rule must have a quality
// measurement function (since they are sorted before
// those without), and we need to check if there is
// a better quality match
T.order === R && T.quality)
);
if (u == null || p == null)
throw new Error("Could not find a matching rule for the below content. The rule with highest `order` should always match content provided to it. Check the definition of `match` for '" + a[a.length - 1] + `'. It seems to not match the following source:
` + l);
if (p.index)
throw new Error("`match` must return a capture starting at index 0 (the current parse index). Did you forget a ^ at the start of the RegExp?");
var f = u.parse(p, o, c);
if (Array.isArray(f))
Array.prototype.push.apply(_, f);
else {
if (f == null || typeof f != "object")
throw new Error(`parse() function returned invalid parse result: '${f}'`);
f.type == null && (f.type = d), _.push(f);
}
c.prevCapture = p, l = l.substring(c.prevCapture[0].length);
}
return _;
}, s = function(l, c) {
return r = Vl(c, t), !r.inline && !r.disableAutoBlockNewlines && (l = l + `
`), r.prevCapture = null, i(Hl(l), r);
};
return s;
}, me = function(e) {
var t = function(r, i, s) {
return i.inline ? e.exec(r) : null;
};
return t.regex = e, t;
}, Se = function(e) {
var t = function(r, i) {
return i.inline ? null : e.exec(r);
};
return t.regex = e, t;
}, Pr = function(e) {
var t = function(r, i) {
return e.exec(r);
};
return t.regex = e, t;
}, N_ = typeof Symbol == "function" && Symbol.for && Symbol.for("react.element") || 60103, J = function(e, t, a) {
var r = {
$$typeof: N_,
type: e,
key: t ?? void 0,
ref: null,
props: a,
_owner: null
};
return r;
}, ae = function(e, t, a, r) {
a = a || {}, r = typeof r < "u" ? r : !0;
var i = "";
for (var s in a) {
var o = a[s];
Object.prototype.hasOwnProperty.call(a, s) && o && (i += " " + Le(s) + '="' + Le(o) + '"');
}
var l = "<" + e + i + ">";
return r ? l + t + "</" + e + ">" : l;
}, Zr = {}, ke = function(e) {
if (e == null)
return null;
try {
var t = new URL(e, "https://localhost").protocol;
if (t.indexOf("javascript:") === 0 || t.indexOf("vbscript:") === 0 || t.indexOf("data:") === 0)
return null;
} catch {
return null;
}
return e;
}, O_ = /[<>&"']/g, I_ = {
"<": "<",
">": ">",
"&": "&",
'"': """,
"'": "'",
"/": "/",
"`": "`"
}, Le = function(e) {
return String(e).replace(O_, function(t) {
return I_[t];
});
}, A_ = /\\([^0-9A-Za-z\s])/g, wr = function(e) {
return e.replace(A_, "$1");
}, We = function(e, t, a) {
var r = a.inline || !1;
a.inline = !0;
var i = e(t, a);
return a.inline = r, i;
}, v_ = function(e, t, a) {
var r = a.inline || !1;
a.inline = !1;
var i = e(t + `
`, a);
return a.inline = r, i;
}, qe = function(e, t, a) {
return {
content: We(t, e[1], a)
};
}, tt = function() {
return {};
}, Ke = "(?:[*+-]|\\d+\\.)", Wl = "( *)(" + Ke + ") +", Jr = new RegExp("^" + Wl), h_ = new RegExp(Wl + "[^\\n]*(?:\\n(?!\\1" + Ke + ` )[^\\n]*)*(
|$)`, "gm"), Kl = /\n{2,}$/, y_ = /^ (?= *`)|(` *) $/g, D_ = Kl, jr = / *\n+$/, M_ = new RegExp("^( *)(" + Ke + `) [\\s\\S]+?(?:
{2,}(?! )(?!\\1` + Ke + ` )\\n*|\\s*
*$)`), L_ = /(?:^|\n)( *)$/, He = function() {
var n = /^ *\| *| *\| *$/g, e = / *$/, t = /^ *-+: *$/, a = /^ *:-+: *$/, r = /^ *:-+ *$/, i = function(d) {
return t.test(d) ? "right" : a.test(d) ? "center" : r.test(d) ? "left" : null;
}, s = function(d, u, p, E) {
E && (d = d.replace(n, ""));
var S = d.trim().split("|");
return S.map(i);
}, o = function(d, u, p, E) {
var S = p.inTable;
p.inTable = !0;
var g = u(d.trim(), p);
p.inTable = S;
var T = [[]];
return g.forEach(function(R, C) {
R.type === "tableSeparator" ? (!E || C !== 0 && C !== g.length - 1) && T.push([]) : (R.type === "text" && (g[C + 1] == null || g[C + 1].type === "tableSeparator") && (R.content = R.content.replace(e, "")), T[T.length - 1].push(R));
}), T;
}, l = function(d, u, p, E) {
var S = d.trim().split(`
`);
return S.map(function(g) {
return o(g, u, p, E);
});
}, c = function(d) {
return function(u, p, E) {
E.inline = !0;
var S = o(u[1], p, E, d), g = s(u[2], p, E, d), T = l(u[3], p, E, d);
return E.inline = !1, {
type: "table",
header: S,
align: g,
cells: T
};
};
};
return {
parseTable: c(!0),
parseNpTable: c(!1),
TABLE_REGEX: /^ *(\|.+)\n *\|( *[-:]+[-| :]*)\n((?: *\|.*(?:\n|$))*)\n*/,
NPTABLE_REGEX: /^ *(\S.*\|.*)\n *([-:]+ *\|[-| :]*)\n((?:.*\|.*(?:\n|$))*)\n*/
};
}(), Ve = "(?:\\[[^\\]]*\\]|[^\\[\\]]|\\](?=[^\\[]*\\]))*", ei = `\\s*<?((?:\\([^)]*\\)|[^\\s\\\\]|\\\\.)*?)>?(?:\\s+['"]([\\s\\S]*?)['"])?\\s*`, x_ = /mailto:/i, ti = function(e, t, a) {
var r = (e[2] || e[1]).replace(/\s+/g, " ").toLowerCase();
if (t._defs && t._defs[r]) {
var i = t._defs[r];
a.target = i.target, a.title = i.title;
}
return t._refs = t._refs || {}, t._refs[r] = t._refs[r] || [], t._refs[r].push(a), a;
}, $ = 0, Ge = {
Array: {
react: function(n, e, t) {
for (var a = t.key, r = [], i = 0, s = 0; i < n.length; i++, s++) {
t.key = "" + i;
var o = n[i];
if (o.type === "text")
for (o = {
type: "text",
content: o.content
}; i + 1 < n.length && n[i + 1].type === "text"; i++)
o.content += n[i + 1].content;
r.push(e(o, t));
}
return t.key = a, r;
},
html: function(n, e, t) {
for (var a = "", r = 0; r < n.length; r++) {
var i = n[r];
if (i.type === "text")
for (i = {
type: "text",
content: i.content
}; r + 1 < n.length && n[r + 1].type === "text"; r++)
i.content += n[r + 1].content;
a += e(i, t);
}
return a;
}
},
heading: {
order: $++,
match: Se(/^ *(#{1,6})([^\n]+?)#* *(?:\n *)+\n/),
parse: function(n, e, t) {
return {
level: n[1].length,
content: We(e, n[2].trim(), t)
};
},
react: function(n, e, t) {
return J("h" + n.level, t.key, {
children: e(n.content, t)
});
},
html: function(n, e, t) {
return ae("h" + n.level, e(n.content, t));
}
},
nptable: {
order: $++,
match: Se(He.NPTABLE_REGEX),
parse: He.parseNpTable,
react: null,
html: null
},
lheading: {
order: $++,
match: Se(/^([^\n]+)\n *(=|-){3,} *(?:\n *)+\n/),
parse: function(n, e, t) {
return {
type: "heading",
level: n[2] === "=" ? 1 : 2,
content: We(e, n[1], t)
};
},
react: null,
html: null
},
hr: {
order: $++,
match: Se(/^( *[-*_]){3,} *(?:\n *)+\n/),
parse: tt,
react: function(n, e, t) {
return J("hr", t.key, Zr);
},
html: function(n, e, t) {
return "<hr>";
}
},
codeBlock: {
order: $++,
match: Se(/^(?: [^\n]+\n*)+(?:\n *)+\n/),
parse: function(n, e, t) {
var a = n[0].replace(/^ /gm, "").replace(/\n+$/, "");
return {
lang: void 0,
content: a
};
},
react: function(n, e, t) {
var a = n.lang ? "markdown-code-" + n.lang : void 0;
return J("pre", t.key, {
children: J("code", null, {
className: a,
children: n.content
})
});
},
html: function(n, e, t) {
var a = n.lang ? "markdown-code-" + n.lang : void 0, r = ae("code", Le(n.content), {
class: a
});
return ae("pre", r);
}
},
fence: {
order: $++,
match: Se(/^ *(`{3,}|~{3,}) *(?:(\S+) *)?\n([\s\S]+?)\n?\1 *(?:\n *)+\n/),
parse: function(n, e, t) {
return {
type: "codeBlock",
lang: n[2] || void 0,
content: n[3]
};
},
react: null,
html: null
},
blockQuote: {
order: $++,
match: Se(/^( *>[^\n]+(\n[^\n]+)*\n*)+\n{2,}/),
parse: function(n, e, t) {
var a = n[0].replace(/^ *> ?/gm, "");
return {
content: e(a, t)
};
},
react: function(n, e, t) {
return J("blockquote", t.key, {
children: e(n.content, t)
});
},
html: function(n, e, t) {
return ae("blockquote", e(n.content, t));
}
},
list: {
order: $++,
match: function(n, e) {
var t = e.prevCapture == null ? "" : e.prevCapture[0], a = L_.exec(t), r = e._list || !e.inline;
return a && r ? (n = a[1] + n, M_.exec(n)) : null;
},
parse: function(n, e, t) {
var a = n[2], r = a.length > 1, i = r ? +a : void 0, s = n[0].replace(D_, `
`).match(h_), o = !1, l = s.map(function(c, _) {
var d = Jr.exec(c), u = d ? d[0].length : 0, p = new RegExp("^ {1," + u + "}", "gm"), E = c.replace(p, "").replace(Jr, ""), S = _ === s.length - 1, g = E.indexOf(`
`) !== -1, T = g || S && o;
o = T;
var R = t.inline, C = t._list;
t._list = !0;
var N;
T ? (t.inline = !1, N = E.replace(jr, `
`)) : (t.inline = !0, N = E.replace(jr, ""));
var O = e(N, t);
return t.inline = R, t._list = C, O;
});
return {
ordered: r,
start: i,
items: l
};
},
react: function(n, e, t) {
var a = n.ordered ? "ol" : "ul";
return J(a, t.key, {
start: n.start,
children: n.items.map(function(r, i) {
return J("li", "" + i, {
children: e(r, t)
});
})
});
},
html: function(n, e, t) {
var a = n.items.map(function(s) {
return ae("li", e(s, t));
}).join(""), r = n.ordered ? "ol" : "ul", i = {
start: n.start
};
return ae(r, a, i);
}
},
def: {
order: $++,
// TODO(aria): This will match without a blank line before the next
// block element, which is inconsistent with most of the rest of
// simple-markdown.
match: Se(/^ *\[([^\]]+)\]: *<?([^\s>]*)>?(?: +["(]([^\n]+)[")])? *\n(?: *\n)*/),
parse: function(n, e, t) {
var a = n[1].replace(/\s+/g, " ").toLowerCase(), r = n[2], i = n[3];
return t._refs && t._refs[a] && t._refs[a].forEach(function(s) {
s.target = r, s.title = i;
}), t._defs = t._defs || {}, t._defs[a] = {
target: r,
title: i
}, {
def: a,
target: r,
title: i
};
},
react: function() {
return null;
},
html: function() {
return "";
}
},
table: {
order: $++,
match: Se(He.TABLE_REGEX),
parse: He.parseTable,
react: function(n, e, t) {
var a = function(o) {
return n.align[o] == null ? {} : {
textAlign: n.align[o]
};
}, r = n.header.map(function(s, o) {
return J("th", "" + o, {
style: a(o),
scope: "col",
children: e(s, t)
});
}), i = n.cells.map(function(s, o) {
return J("tr", "" + o, {
children: s.map(function(l, c) {
return J("td", "" + c, {
style: a(c),
children: e(l, t)
});
})
});
});
return J("table", t.key, {
children: [J("thead", "thead", {
children: J("tr", null, {
children: r
})
}), J("tbody", "tbody", {
children: i
})]
});
},
html: function(n, e, t) {
var a = function(c) {
return n.align[c] == null ? "" : "text-align:" + n.align[c] + ";";
}, r = n.header.map(function(l, c) {
return ae("th", e(l, t), {
style: a(c),
scope: "col"
});
}).join(""), i = n.cells.map(function(l) {
var c = l.map(function(_, d) {
return ae("td", e(_, t), {
style: a(d)
});
}).join("");
return ae("tr", c);
}).join(""), s = ae("thead", ae("tr", r)), o = ae("tbody", i);
return ae("table", s + o);
}
},
newline: {
order: $++,
match: Se(/^(?:\n *)*\n/),
parse: tt,
react: function(n, e, t) {
return `
`;
},
html: function(n, e, t) {
return `
`;
}
},
paragraph: {
order: $++,
match: Se(/^((?:[^\n]|\n(?! *\n))+)(?:\n *)+\n/),
parse: qe,
react: function(n, e, t) {
return J("div", t.key, {
className: "paragraph",
children: e(n.content, t)
});
},
html: function(n, e, t) {
var a = {
class: "paragraph"
};
return ae("div", e(n.content, t), a);
}
},
escape: {
order: $++,
// We don't allow escaping numbers, letters, or spaces here so that
// backslashes used in plain text still get rendered. But allowing
// escaping anything else provides a very flexible escape mechanism,
// regardless of how this grammar is extended.
match: me(/^\\([^0-9A-Za-z\s])/),
parse: function(n, e, t) {
return {
type: "text",
content: n[1]
};
},
react: null,
html: null
},
tableSeparator: {
order: $++,
match: function(n, e) {
return e.inTable ? /^ *\| */.exec(n) : null;
},
parse: function() {
return {
type: "tableSeparator"
};
},
// These shouldn't be reached, but in case they are, be reasonable:
react: function() {
return " | ";
},
html: function() {
return " | ";
}
},
autolink: {
order: $++,
match: me(/^<([^: >]+:\/[^ >]+)>/),
parse: function(n, e, t) {
return {
type: "link",
content: [{
type: "text",
content: n[1]
}],
target: n[1]
};
},
react: null,
html: null
},
mailto: {
order: $++,
match: me(/^<([^ >]+@[^ >]+)>/),
parse: function(n, e, t) {
var a = n[1], r = n[1];
return x_.test(r) || (r = "mailto:" + r), {
type: "link",
content: [{
type: "text",
content: a
}],
target: r
};
},
react: null,
html: null
},
url: {
order: $++,
match: me(/^(https?:\/\/[^\s<]+[^<.,:;"')\]\s])/),
parse: function(n, e, t) {
return {
type: "link",
content: [{
type: "text",
content: n[1]
}],
target: n[1],
title: void 0
};
},
react: null,
html: null
},
link: {
order: $++,
match: me(new RegExp("^\\[(" + Ve + ")\\]\\(" + ei + "\\)")),
parse: function(n, e, t) {
var a = {
content: e(n[1], t),
target: wr(n[2]),
title: n[3]
};
return a;
},
react: function(n, e, t) {
return J("a", t.key, {
href: ke(n.target),
title: n.title,
children: e(n.content, t)
});
},
html: function(n, e, t) {
var a = {
href: ke(n.target),
title: n.title
};
return ae("a", e(n.content, t), a);
}
},
image: {
order: $++,
match: me(new RegExp("^!\\[(" + Ve + ")\\]\\(" + ei + "\\)")),
parse: function(n, e, t) {
var a = {
alt: n[1],
target: wr(n[2]),
title: n[3]
};
return a;
},
react: function(n, e, t) {
return J("img", t.key, {
src: ke(n.target),
alt: n.alt,
title: n.title
});
},
html: function(n, e, t) {
var a = {
src: ke(n.target),
alt: n.alt,
title: n.title
};
return ae("img", "", a, !1);
}
},
reflink: {
order: $++,
match: me(new RegExp(
// The first [part] of the link
"^\\[(" + Ve + ")\\]\\s*\\[([^\\]]*)\\]"
)),
parse: function(n, e, t) {
return ti(n, t, {
type: "link",
content: e(n[1], t)
});
},
react: null,
html: null
},
refimage: {
order: $++,
match: me(new RegExp(
// The first [part] of the link
"^!\\[(" + Ve + ")\\]\\s*\\[([^\\]]*)\\]"
)),
parse: function(n, e, t) {
return ti(n, t, {
type: "image",
alt: n[1]
});
},
react: null,
html: null
},
em: {
order: $,
match: me(new RegExp(
// only match _s surrounding words.
"^\\b_((?:__|\\\\[\\s\\S]|[^\\\\_])+?)_\\b|^\\*(?=\\S)((?:\\*\\*|\\\\[\\s\\S]|\\s+(?:\\\\[\\s\\S]|[^\\s\\*\\\\]|\\*\\*)|[^\\s\\*\\\\])+?)\\*(?!\\*)"
)),
quality: function(n) {
return n[0].length + 0.2;
},
parse: function(n, e, t) {
return {
content: e(n[2] || n[1], t)
};
},
react: function(n, e, t) {
return J("em", t.key, {
children: e(n.content, t)
});
},
html: function(n, e, t) {
return ae("em", e(n.content, t));
}
},
strong: {
order: $,
match: me(/^\*\*((?:\\[\s\S]|[^\\])+?)\*\*(?!\*)/),
quality: function(n) {
return n[0].length + 0.1;
},
parse: qe,
react: function(n, e, t) {
return J("strong", t.key, {
children: e(n.content, t)
});
},
html: function(n, e, t) {
return ae("strong", e(n.content, t));
}
},
u: {
order: $++,
match: me(/^__((?:\\[\s\S]|[^\\])+?)__(?!_)/),
quality: function(n) {
return n[0].length;
},
parse: qe,
react: function(n, e, t) {
return J("u", t.key, {
children: e(n.content, t)
});
},
html: function(n, e, t) {
return ae("u", e(n.content, t));
}
},
del: {
order: $++,
match: me(/^~~(?=\S)((?:\\[\s\S]|~(?!~)|[^\s~\\]|\s(?!~~))+?)~~/),
parse: qe,
react: function(n, e, t) {
return J("del", t.key, {
children: e(n.content, t)
});
},
html: function(n, e, t) {
return ae("del", e(n.content, t));
}
},
inlineCode: {
order: $++,
match: me(/^(`+)([\s\S]*?[^`])\1(?!`)/),
parse: function(n, e, t) {
return {
content: n[2].replace(y_, "$1")
};
},
react: function(n, e, t) {
return J("code", t.key, {
children: n.content
});
},
html: function(n, e, t) {
return ae("code", Le(n.content));
}
},
br: {
order: $++,
match: Pr(/^ {2,}\n/),
parse: tt,
react: function(n, e, t) {
return J("br", t.key, Zr);
},
html: function(n, e, t) {
return "<br>";
}
},
text: {
order: $++,
// Here we look for anything followed by non-symbols,
// double newlines, or double-space-newlines
// We break on any symbol characters so that this grammar
// is easy to extend without needing to modify this regex
match: Pr(/^[\s\S]+?(?=[^0-9A-Za-z\s\u00c0-\uffff]|\n\n| {2,}\n|\w+:\S|$)/),
parse: function(n, e, t) {
return {
content: n[0]
};
},
react: function(n, e, t) {
return n.content;
},
html: function(n, e, t) {
return Le(n.content);
}
}
}, P_ = function(e, t) {
!t && typeof console < "u" && console.warn("simple-markdown ruleOutput should take 'react' or 'html' as the second argument.");
var a = function(i, s, o) {
return e[i.type][t](i, s, o);
};
return a;
}, w_ = function(e) {
var t = function a(r, i) {
if (i = i || {}, Array.isArray(r)) {
for (var s = i.key, o = [], l = null, c = 0; c < r.length; c++) {
i.key = "" + c;
var _ = a(r[c], i);
typeof _ == "string" && typeof l == "string" ? (l = l + _, o[o.length - 1] = l) : (o.push(_), l = _);
}
return i.key = s, o;
} else
return e(r, a, i);
};
return t;
}, k_ = function(e) {
var t = function a(r, i) {
return i = i || {}, Array.isArray(r) ? r.map(function(s) {
return a(s, i);
}).join("") : e(r, a, i);
};
return t;
}, Fr = function(e, t, a = {}) {
if (!t)
throw new Error("simple-markdown: outputFor: `property` must be defined. if you just upgraded, you probably need to replace `outputFor` with `reactFor`");
var r, i = e.Array || Ge.Array, s = i[t];
if (!s)
throw new Error("simple-markdown: outputFor: to join nodes of type `" + // @ts-expect-error - TS2469 - The '+' operator cannot be applied to type 'symbol'.
t + "` you must provide an `Array:` joiner rule with that type, Please see the docs for details on specifying an Array rule.");
var o = s, l = function _(d, u) {
return u = u || r, r = u, Array.isArray(d) ? o(d, _, u) : e[d.type][t](d, _, u);
}, c = function(d, u) {
return r = Vl(u, a), l(d, r);
};
return c;
}, Qe = zl(Ge), Br = function(e, t) {
return t = t || {}, t.inline = !1, Qe(e, t);
}, U_ = function(e, t) {
return t = t || {}, t.inline = !0, Qe(e, t);
}, ni = function(e, t) {
var a = Kl.test(e);
return t = t || {}, t.inline = !a, Qe(e, t);
}, kr = Fr(Ge, "react"), $l = Fr(Ge, "html"), Ql = function(e, t) {
return kr(Br(e, t), t);
}, F_ = function(e, t) {
return $l(Br(e, t), t);
}, B_ = function(e) {
var t = {};
for (var a in e)
a !== "source" && Object.prototype.hasOwnProperty.call(e, a) && (t[a] = e[a]);
return t.children = Ql(e.source), J("div", null, t);
}, z = {
defaultRules: Ge,
parserFor: zl,
outputFor: Fr,
inlineRegex: me,
blockRegex: Se,
anyScopeRegex: Pr,
parseInline: We,
parseBlock: v_,
// default wrappers:
markdownToReact: Ql,
markdownToHtml: F_,
ReactMarkdown: B_,
defaultBlockParse: Br,
defaultInlineParse: U_,
defaultImplicitParse: ni,
defaultReactOutput: kr,
defaultHtmlOutput: $l,
preprocess: Hl,
sanitizeText: Le,
sanitizeUrl: ke,
unescapeUrl: wr,
htmlTag: ae,
reactElement: J,
// deprecated:
defaultRawParse: Qe,
ruleOutput: P_,
reactFor: w_,
htmlFor: k_,
defaultParse: function(...n) {
return typeof console < "u" && console.warn("defaultParse is deprecated, please use `defaultImplicitParse`"), ni.apply(null, n);
},
defaultOutput: function(...n) {
return typeof console < "u" && console.warn("defaultOutput is deprecated, please use `defaultReactOutput`"), kr.apply(null, n);
}
};
function G_(n) {
return n && n.__esModule && Object.prototype.hasOwnProperty.call(n, "default") ? n.default : n;
}
function Xl(n) {
return n instanceof Map ? n.clear = n.delete = n.set = function() {
throw new Error("map is read-only");
} : n instanceof Set && (n.add = n.clear = n.delete = function() {
throw new Error("set is read-only");
}), Object.freeze(n), Object.getOwnPropertyNames(n).forEach((e) => {
const t = n[e], a = typeof t;
(a === "object" || a === "function") && !Object.isFrozen(t) && Xl(t);
}), n;
}
class ai {
/**
* @param {CompiledMode} mode
*/
constructor(e) {
e.data === void 0 && (e.data = {}), this.data = e.data, this.isMatchIgnored = !1;
}
ignoreMatch() {
this.isMatchIgnored = !0;
}
}
function Zl(n) {
return n.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
}
function Ne(n, ...e) {
const t = /* @__PURE__ */ Object.create(null);
for (const a in n)
t[a] = n[a];
return e.forEach(function(a) {
for (const r in a)
t[r] = a[r];
}), /** @type {T} */
t;
}
const Y_ = "</span>", ri = (n) => !!n.scope, q_ = (n, { prefix: e }) => {
if (n.startsWith("language:"))
return n.replace("language:", "language-");
if (n.includes(".")) {
const t = n.split(".");
return [
`${e}${t.shift()}`,
...t.map((a, r) => `${a}${"_".repeat(r + 1)}`)
].join(" ");
}
return `${e}${n}`;
};
class H_ {
/**
* Creates a new HTMLRenderer
*
* @param {Tree} parseTree - the parse tree (must support `walk` API)
* @param {{classPrefix: string}} options
*/
constructor(e, t) {
this.buffer = "", this.classPrefix = t.classPrefix, e.walk(this);
}
/**
* Adds texts to the output stream
*
* @param {string} text */
addText(e) {
this.buffer += Zl(e);
}
/**
* Adds a node open to the output stream (if needed)
*
* @param {Node} node */
openNode(e) {
if (!ri(e))
return;
const t = q_(
e.scope,
{ prefix: this.classPrefix }
);
this.span(t);
}
/**
* Adds a node close to the output stream (if needed)
*
* @param {Node} node */
closeNode(e) {
ri(e) && (this.buffer += Y_);
}
/**
* returns the accumulated buffer
*/
value() {
return this.buffer;
}
// helpers
/**
* Builds a span element
*
* @param {string} className */
span(e) {
this.buffer += `<span class="${e}">`;
}
}
const ii = (n = {}) => {
const e = { children: [] };
return Object.assign(e, n), e;
};
class Gr {
constructor() {
this.rootNode = ii(), this.stack = [this.rootNode];
}
get top() {
return this.stack[this.stack.length - 1];
}
get root() {
return this.rootNode;
}
/** @param {Node} node */
add(e) {
this.top.children.push(e);
}
/** @param {string} scope */
openNode(e) {
const t = ii({ scope: e });
this.add(t), this.stack.push(t);
}
closeNode() {
if (this.stack.length > 1)
return this.stack.pop();
}
closeAllNodes() {
for (; this.closeNode(); )
;
}
toJSON() {
return JSON.stringify(this.rootNode, null, 4);
}
/**
* @typedef { import("./html_renderer").Renderer } Renderer
* @param {Renderer} builder
*/
walk(e) {
return this.constructor._walk(e, this.rootNode);
}
/**
* @param {Renderer} builder
* @param {Node} node
*/
static _walk(e, t) {
return typeof t == "string" ? e.addText(t) : t.children && (e.openNode(t), t.children.forEach((a) => this._walk(e, a)), e.closeNode(t)), e;
}
/**
* @param {Node} node
*/
static _collapse(e) {
typeof e != "string" && e.children && (e.children.every((t) => typeof t == "string") ? e.children = [e.children.join("")] : e.children.forEach((t) => {
Gr._collapse(t);
}));
}
}
class V_ extends Gr {
/**
* @param {*} options
*/
constructor(e) {
super(), this.options = e;
}
/**
* @param {string} text
*/
addText(e) {
e !== "" && this.add(e);
}
/** @param {string} scope */
startScope(e) {
this.openNode(e);
}
endScope() {
this.closeNode();
}
/**
* @param {Emitter & {root: DataNode}} emitter
* @param {string} name
*/
__addSublanguage(e, t) {
const a = e.root;
t && (a.scope = `language:${t}`), this.add(a);
}
toHTML() {
return new H_(this, this.options).value();
}
finalize() {
return this.closeAllNodes(), !0;
}
}
function Ue(n) {
return n ? typeof n == "string" ? n : n.source : null;
}
function Jl(n) {
return Ae("(?=", n, ")");
}
function z_(n) {
return Ae("(?:", n, ")*");
}
function W_(n) {
return Ae("(?:", n, ")?");
}
function Ae(...n) {
return n.map((t) => Ue(t)).join("");
}
function K_(n) {
const e = n[n.length - 1];
return typeof e == "object" && e.constructor === Object ? (n.splice(n.length - 1, 1), e) : {};
}
function Yr(...n) {
return "(" + (K_(n).capture ? "" : "?:") + n.map((a) => Ue(a)).join("|") + ")";
}
function jl(n) {
return new RegExp(n.toString() + "|").exec("").length - 1;
}
function $_(n, e) {
const t = n && n.exec(e);
return t && t.index === 0;
}
const Q_ = /\[(?:[^\\\]]|\\.)*\]|\(\??|\\([1-9][0-9]*)|\\./;
function qr(n, { joinWith: e }) {
let t = 0;
return n.map((a) => {
t += 1;
const r = t;
let i = Ue(a), s = "";
for (; i.length > 0; ) {
const o = Q_.exec(i);
if (!o) {
s += i;
break;
}
s += i.substring(0, o.index), i = i.substring(o.index + o[0].length), o[0][0] === "\\" && o[1] ? s += "\\" + String(Number(o[1]) + r) : (s += o[0], o[0] === "(" && t++);
}
return s;
}).map((a) => `(${a})`).join(e);
}
const X_ = /\b\B/, ec = "[a-zA-Z]\\w*", Hr = "[a-zA-Z_]\\w*", tc = "\\b\\d+(\\.\\d+)?", nc = "(-?)(\\b0[xX][a-fA-F0-9]+|(\\b\\d+(\\.\\d*)?|\\.\\d+)([eE][-+]?\\d+)?)", ac = "\\b(0b[01]+)", Z_ = "!|!=|!==|%|%=|&|&&|&=|\\*|\\*=|\\+|\\+=|,|-|-=|/=|/|:|;|<<|<<=|<=|<|===|==|=|>>>=|>>=|>=|>>>|>>|>|\\?|\\[|\\{|\\(|\\^|\\^=|\\||\\|=|\\|\\||~", J_ = (n = {}) => {
const e = /^#![ ]*\//;
return n.binary && (n.begin = Ae(
e,
/.*\b/,
n.binary,
/\b.*/
)), Ne({
scope: "meta",
begin: e,
end: /$/,
relevance: 0,
/** @type {ModeCallback} */
"on:begin": (t, a) => {
t.index !== 0 && a.ignoreMatch();
}
}, n);
}, Fe = {
begin: "\\\\[\\s\\S]",
relevance: 0
}, j_ = {
scope: "string",
begin: "'",
end: "'",
illegal: "\\n",
contains: [Fe]
}, ed = {
scope: "string",
begin: '"',
end: '"',
illegal: "\\n",
contains: [Fe]
}, td = {
begin: /\b(a|an|the|are|I'm|isn't|don't|doesn't|won't|but|just|should|pretty|simply|enough|gonna|going|wtf|so|such|will|you|your|they|like|more)\b/
}, Xe = function(n, e, t = {}) {
const a = Ne(
{
scope: "comment",
begin: n,
end: e,
contains: []
},
t
);
a.contains.push({
scope: "doctag",
// hack to avoid the space from being included. the space is necessary to
// match here to prevent the plain text rule below from gobbling up doctags
begin: "[ ]*(?=(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):)",
end: /(TODO|FIXME|NOTE|BUG|OPTIMIZE|HACK|XXX):/,
excludeBegin: !0,
relevance: 0
});
const r = Yr(
// list of common 1 and 2 letter words in English
"I",
"a",
"is",
"so",
"us",
"to",
"at",
"if",
"in",
"it",
"on",
// note: this is not an exhaustive list of contractions, just popular ones
/[A-Za-z]+['](d|ve|re|ll|t|s|n)/,
// contractions - can't we'd they're let's, etc
/[A-Za-z]+[-][a-z]+/,
// `no-way`, etc.
/[A-Za-z][a-z]{2,}/
// allow capitalized words at beginning of sentences
);
return a.contains.push(
{
// TODO: how to include ", (, ) without breaking grammars that use these for
// comment delimiters?
// begin: /[ ]+([()"]?([A-Za-z'-]{3,}|is|a|I|so|us|[tT][oO]|at|if|in|it|on)[.]?[()":]?([.][ ]|[ ]|\))){3}/
// ---
// this tries to find sequences of 3 english words in a row (without any
// "programming" type syntax) this gives us a strong signal that we've
// TRULY found a comment - vs perhaps scanning with the wrong language.
// It's possible to find something that LOOKS like the start of the
// comment - but then if there is no readable text - good chance it is a
// false match and not a comment.
//
// for a visual example please see:
// https://github.com/highlightjs/highlight.js/issues/2827
begin: Ae(
/[ ]+/,
// necessary to prevent us gobbling up doctags like /* @author Bob Mcgill */
"(",
r,
/[.]?[:]?([.][ ]|[ ])/,
"){3}"
)
// look for 3 words in a row
}
), a;
}, nd = Xe("//", "$"), ad = Xe("/\\*", "\\*/"), rd = Xe("#", "$"), id = {
scope: "number",
begin: tc,
relevance: 0
}, od = {
scope: "number",
begin: nc,
relevance: 0
}, sd = {
scope: "number",
begin: ac,
relevance: 0
}, ld = {
scope: "regexp",
begin: /\/(?=[^/\n]*\/)/,
end: /\/[gimuy]*/,
contains: [
Fe,
{
begin: /\[/,
end: /\]/,
relevance: 0,
contains: [Fe]
}
]
}, cd = {
scope: "title",
begin: ec,
relevance: 0
}, _d = {
scope: "title",
begin: Hr,
relevance: 0
}, dd = {
// excludes method names from keyword processing
begin: "\\.\\s*" + Hr,
relevance: 0
}, ud = function(n) {
return Object.assign(
n,
{
/** @type {ModeCallback} */
"on:begin": (e, t) => {
t.data._beginMatch = e[1];
},
/** @type {ModeCallback} */
"on:end": (e, t) => {
t.data._beginMatch !== e[1] && t.ignoreMatch();
}
}
);
};
var ze = /* @__PURE__ */ Object.freeze({
__proto__: null,
APOS_STRING_MODE: j_,
BACKSLASH_ESCAPE: Fe,
BINARY_NUMBER_MODE: sd,
BINARY_NUMBER_RE: ac,
COMMENT: Xe,
C_BLOCK_COMMENT_MODE: ad,
C_LINE_COMMENT_MODE: nd,
C_NUMBER_MODE: od,
C_NUMBER_RE: nc,
END_SAME_AS_BEGIN: ud,
HASH_COMMENT_MODE: rd,
IDENT_RE: ec,
MATCH_NOTHING_RE: X_,
METHOD_GUARD: dd,
NUMBER_MODE: id,
NUMBER_RE: tc,
PHRASAL_WORDS_MODE: td,
QUOTE_STRING_MODE: ed,
REGEXP_MODE: ld,
RE_STARTERS_RE: Z_,
SHEBANG: J_,
TITLE_MODE: cd,
UNDERSCORE_IDENT_RE: Hr,
UNDERSCORE_TITLE_MODE: _d
});
function md(n, e) {
n.input[n.index - 1] === "." && e.ignoreMatch();
}
function pd(n, e) {
n.className !== void 0 && (n.scope = n.className, delete n.className);
}
function Ed(n, e) {
e && n.beginKeywords && (n.begin = "\\b(" + n.beginKeywords.split(" ").join("|") + ")(?!\\.)(?=\\b|\\s)", n.__beforeBegin = md, n.keywords = n.keywords || n.beginKeywords, delete n.beginKeywords, n.relevance === void 0 && (n.relevance = 0));
}
function Sd(n, e) {
Array.isArray(n.illegal) && (n.illegal = Yr(...n.illegal));
}
function gd(n, e) {
if (n.match) {
if (n.begin || n.end)
throw new Error("begin & end are not supported with match");
n.begin = n.match, delete n.match;
}
}
function Td(n, e) {
n.relevance === void 0 && (n.relevance = 1);
}
const bd = (n, e) => {
if (!n.beforeMatch)
return;
if (n.starts)
throw new Error("beforeMatch cannot be used with starts");
const t = Object.assign({}, n);
Object.keys(n).forEach((a) => {
delete n[a];
}), n.keywords = t.keywords, n.begin = Ae(t.beforeMatch, Jl(t.begin)), n.starts = {
relevance: 0,
contains: [
Object.assign(t, { endsParent: !0 })
]
}, n.relevance = 0, delete t.beforeMatch;
}, Rd = [
"of",
"and",
"for",
"in",
"not",
"or",
"if",
"then",
"parent",
// common variable name
"list",
// common variable name
"value"
// common variable name
], fd = "keyword";
function rc(n, e, t = fd) {
const a = /* @__PURE__ */ Object.create(null);
return typeof n == "string" ? r(t, n.split(" ")) : Array.isArray(n) ? r(t, n) : Object.keys(n).forEach(function(i) {
Object.assign(
a,
rc(n[i], e, i)
);
}), a;
function r(i, s) {
e && (s = s.map((o) => o.toLowerCase())), s.forEach(function(o) {
const l = o.split("|");
a[l[0]] = [i, Cd(l[0], l[1])];
});
}
}
function Cd(n, e) {
return e ? Number(e) : Nd(n) ? 0 : 1;
}
function Nd(n) {
return Rd.includes(n.toLowerCase());
}
const oi = {}, Ie = (n) => {
console.error(n);
}, si = (n, ...e) => {
console.log(`WARN: ${n}`, ...e);
}, Me = (n, e) => {
oi[`${n}/${e}`] || (console.log(`Deprecated as of ${n}. ${e}`), oi[`${n}/${e}`] = !0);
}, $e = new Error();
function ic(n, e, { key: t }) {
let a = 0;
const r = n[t], i = {}, s = {};
for (let o = 1; o <= e.length; o++)
s[o + a] = r[o], i[o + a] = !0, a += jl(e[o - 1]);
n[t] = s, n[t]._emit = i, n[t]._multi = !0;
}
function Od(n) {
if (Array.isArray(n.begin)) {
if (n.skip || n.excludeBegin || n.returnBegin)
throw Ie("skip, excludeBegin, returnBegin not compatible with beginScope: {}"), $e;
if (typeof n.beginScope != "object" || n.beginScope === null)
throw Ie("beginScope must be object"), $e;
ic(n, n.begin, { key: "beginScope" }), n.begin = qr(n.begin, { joinWith: "" });
}
}
function Id(n) {
if (Array.isArray(n.end)) {
if (n.skip || n.excludeEnd || n.returnEnd)
throw Ie("skip, excludeEnd, returnEnd not compatible with endScope: {}"), $e;
if (typeof n.endScope != "object" || n.endScope === null)
throw Ie("endScope must be object"), $e;
ic(n, n.end, { key: "endScope" }), n.end = qr(n.end, { joinWith: "" });
}
}
function Ad(n) {
n.scope && typeof n.scope == "object" && n.scope !== null && (n.beginScope = n.scope, delete n.scope);
}
function vd(n) {
Ad(n), typeof n.beginScope == "string" && (n.beginScope = { _wrap: n.beginScope }), typeof n.endScope == "string" && (n.endScope = { _wrap: n.endScope }), Od(n), Id(n);
}
function hd(n) {
function e(s, o) {
return new RegExp(
Ue(s),
"m" + (n.case_insensitive ? "i" : "") + (n.unicodeRegex ? "u" : "") + (o ? "g" : "")
);
}
class t {
constructor() {
this.matchIndexes = {}, this.regexes = [], this.matchAt = 1, this.position = 0;
}
// @ts-ignore
addRule(o, l) {
l.position = this.position++, this.matchIndexes[this.matchAt] = l, this.regexes.push([l, o]), this.matchAt += jl(o) + 1;
}
compile() {
this.regexes.length === 0 && (this.exec = () => null);
const o = this.regexes.map((l) => l[1]);
this.matcherRe = e(qr(o, { joinWith: "|" }), !0), this.lastIndex = 0;
}
/** @param {string} s */
exec(o) {
this.matcherRe.lastIndex = this.lastIndex;
const l = this.matcherRe.exec(o);
if (!l)
return null;
const c = l.findIndex((d, u) => u > 0 && d !== void 0), _ = this.matchIndexes[c];
return l.splice(0, c), Object.assign(l, _);
}
}
class a {
constructor() {
this.rules = [], this.multiRegexes = [], this.count = 0, this.lastIndex = 0, this.regexIndex = 0;
}
// @ts-ignore
getMatcher(o) {
if (this.multiRegexes[o])
return this.multiRegexes[o];
const l = new t();
return this.rules.slice(o).forEach(([c, _]) => l.addRule(c, _)), l.compile(), this.multiRegexes[o] = l, l;
}
resumingScanAtSamePosition() {
return this.regexIndex !== 0;
}
considerAll() {
this.regexIndex = 0;
}
// @ts-ignore
addRule(o, l) {
this.rules.push([o, l]), l.type === "begin" && this.count++;
}
/** @param {string} s */
exec(o) {
const l = this.getMatcher(this.regexIndex);
l.lastIndex = this.lastIndex;
let c = l.exec(o);
if (this.resumingScanAtSamePosition() && !(c && c.index === this.lastIndex)) {
const _ = this.getMatcher(0);
_.lastIndex = this.lastIndex + 1, c = _.exec(o);
}
return c && (this.regexIndex += c.position + 1, this.regexIndex === this.count && this.considerAll()), c;
}
}
function r(s) {
const o = new a();
return s.contains.forEach((l) => o.addRule(l.begin, { rule: l, type: "begin" })), s.terminatorEnd && o.addRule(s.terminatorEnd, { type: "end" }), s.illegal && o.addRule(s.illegal, { type: "illegal" }), o;
}
function i(s, o) {
const l = (
/** @type CompiledMode */
s
);
if (s.isCompiled)
return l;
[
pd,
// do this early so compiler extensions generally don't have to worry about
// the distinction between match/begin
gd,
vd,
bd
].forEach((_) => _(s, o)), n.compilerExtensions.forEach((_) => _(s, o)), s.__beforeBegin = null, [
Ed,
// do this later so compiler extensions that come earlier have access to the
// raw array if they wanted to perhaps manipulate it, etc.
Sd,
// default to 1 relevance if not specified
Td
].forEach((_) => _(s, o)), s.isCompiled = !0;
let c = null;
return typeof s.keywords == "object" && s.keywords.$pattern && (s.keywords = Object.assign({}, s.keywords), c = s.keywords.$pattern, delete s.keywords.$pattern), c = c || /\w+/, s.keywords && (s.keywords = rc(s.keywords, n.case_insensitive)), l.keywordPatternRe = e(c, !0), o && (s.begin || (s.begin = /\B|\b/), l.beginRe = e(l.begin), !s.end && !s.endsWithParent && (s.end = /\B|\b/), s.end && (l.endRe = e(l.end)), l.terminatorEnd = Ue(l.end) || "", s.endsWithParent && o.terminatorEnd && (l.terminatorEnd += (s.end ? "|" : "") + o.terminatorEnd)), s.illegal && (l.illegalRe = e(
/** @type {RegExp | string} */
s.illegal
)), s.contains || (s.contains = []), s.contains = [].concat(...s.contains.map(function(_) {
return yd(_ === "self" ? s : _);
})), s.contains.forEach(function(_) {
i(
/** @type Mode */
_,
l
);
}), s.starts && i(s.starts, o), l.matcher = r(l), l;
}
if (n.compilerExtensions || (n.compilerExtensions = []), n.contains && n.contains.includes("self"))
throw new Error("ERR: contains `self` is not supported at the top-level of a language. See documentation.");
return n.classNameAliases = Ne(n.classNameAliases || {}), i(
/** @type Mode */
n
);
}
function oc(n) {
return n ? n.endsWithParent || oc(n.starts) : !1;
}
function yd(n) {
return n.variants && !n.cachedVariants && (n.cachedVariants = n.variants.map(function(e) {
return Ne(n, { variants: null }, e);
})), n.cachedVariants ? n.cachedVariants : oc(n) ? Ne(n, { starts: n.starts ? Ne(n.starts) : null }) : Object.isFrozen(n) ? Ne(n) : n;
}
var Dd = "11.9.0";
class Md extends Error {
constructor(e, t) {
super(e), this.name = "HTMLInjectionError", this.html = t;
}
}
const nt = Zl, li = Ne, ci = Symbol("nomatch"), Ld = 7, sc = function(n) {
const e = /* @__PURE__ */ Object.create(null), t = /* @__PURE__ */ Object.create(null), a = [];
let r = !0;
const i = "Could not find the language '{}', did you forget to load/include a language module?", s = { disableAutodetect: !0, name: "Plain text", contains: [] };
let o = {
ignoreUnescapedHTML: !1,
throwUnescapedHTML: !1,
noHighlightRe: /^(no-?highlight)$/i,
languageDetectRe: /\blang(?:uage)?-([\w-]+)\b/i,
classPrefix: "hljs-",
cssSelector: "pre code",
languages: null,
// beta configuration options, subject to change, welcome to discuss
// https://github.com/highlightjs/highlight.js/issues/1086
__emitter: V_
};
function l(b) {
return o.noHighlightRe.test(b);
}
function c(b) {
let v = b.className + " ";
v += b.parentNode ? b.parentNode.className : "";
const M = o.languageDetectRe.exec(v);
if (M) {
const w = D(M[1]);
return w || (si(i.replace("{}", M[1])), si("Falling back to no-highlight mode for this block.", b)), w ? M[1] : "no-highlight";
}
return v.split(/\s+/).find((w) => l(w) || D(w));
}
function _(b, v, M) {
let w = "", B = "";
typeof v == "object" ? (w = b, M = v.ignoreIllegals, B = v.language) : (Me("10.7.0", "highlight(lang, code, ...args) has been deprecated."), Me("10.7.0", `Please use highlight(code, options) instead.
https://github.com/highlightjs/highlight.js/issues/2277`), B = b, w = v), M === void 0 && (M = !0);
const j = {
code: w,
language: B
};
k("before:highlight", j);
const ne = j.result ? j.result : d(j.language, j.code, M);
return ne.code = j.code, k("after:highlight", ne), ne;
}
function d(b, v, M, w) {
const B = /* @__PURE__ */ Object.create(null);
function j(I, h) {
return I.keywords[h];
}
function ne() {
if (!x.keywords) {
ee.addText(V);
return;
}
let I = 0;
x.keywordPatternRe.lastIndex = 0;
let h = x.keywordPatternRe.exec(V), P = "";
for (; h; ) {
P += V.substring(I, h.index);
const F = _e.case_insensitive ? h[0].toLowerCase() : h[0], le = j(x, F);
if (le) {
const [ue, Pe] = le;
if (ee.addText(P), P = "", B[F] = (B[F] || 0) + 1, B[F] <= Ld && (fe += Pe), ue.startsWith("_"))
P += h[0];
else {
const we = _e.classNameAliases[ue] || ue;
H(h[0], we);
}
} else
P += h[0];
I = x.keywordPatternRe.lastIndex, h = x.keywordPatternRe.exec(V);
}
P += V.substring(I), ee.addText(P);
}
function se() {
if (V === "")
return;
let I = null;
if (typeof x.subLanguage == "string") {
if (!e[x.subLanguage]) {
ee.addText(V);
return;
}
I = d(x.subLanguage, V, !0, ye[x.subLanguage]), ye[x.subLanguage] = /** @type {CompiledMode} */
I._top;
} else
I = p(V, x.subLanguage.length ? x.subLanguage : null);
x.relevance > 0 && (fe += I.relevance), ee.__addSublanguage(I._emitter, I.language);
}
function G() {
x.subLanguage != null ? se() : ne(), V = "";
}
function H(I, h) {
I !== "" && (ee.startScope(h), ee.addText(I), ee.endScope());
}
function W(I, h) {
let P = 1;
const F = h.length - 1;
for (; P <= F; ) {
if (!I._emit[P]) {
P++;
continue;
}
const le = _e.classNameAliases[I[P]] || I[P], ue = h[P];
le ? H(ue, le) : (V = ue, ne(), V = ""), P++;
}
}
function Y(I, h) {
return I.scope && typeof I.scope == "string" && ee.openNode(_e.classNameAliases[I.scope] || I.scope), I.beginScope && (I.beginScope._wrap ? (H(V, _e.classNameAliases[I.beginScope._wrap] || I.beginScope._wrap), V = "") : I.beginScope._multi && (W(I.beginScope, h), V = "")), x = Object.create(I, { parent: { value: x } }), x;
}
function Z(I, h, P) {
let F = $_(I.endRe, P);
if (F) {
if (I["on:end"]) {
const le = new ai(I);
I["on:end"](h, le), le.isMatchIgnored && (F = !1);
}
if (F) {
for (; I.endsParent && I.parent; )
I = I.parent;
return I;
}
}
if (I.endsWithParent)
return Z(I.parent, h, P);
}
function re(I) {
return x.matcher.regexIndex === 0 ? (V += I[0], 1) : (Ee = !0, 0);
}
function ie(I) {
const h = I[0], P = I.rule, F = new ai(P), le = [P.__beforeBegin, P["on:begin"]];
for (const ue of le)
if (ue && (ue(I, F), F.isMatchIgnored))
return re(h);
return P.skip ? V += h : (P.excludeBegin && (V += h), G(), !P.returnBegin && !P.excludeBegin && (V = h)), Y(P, I), P.returnBegin ? 0 : h.length;
}
function de(I) {
const h = I[0], P = v.substring(I.index), F = Z(x, I, P);
if (!F)
return ci;
const le = x;
x.endScope && x.endScope._wrap ? (G(), H(h, x.endScope._wrap)) : x.endScope && x.endScope._multi ? (G(), W(x.endScope, I)) : le.skip ? V += h : (le.returnEnd || le.excludeEnd || (V += h), G(), le.excludeEnd && (V = h));
do
x.scope && ee.closeNode(), !x.skip && !x.subLanguage && (fe += x.relevance), x = x.parent;
while (x !== F.parent);
return F.starts && Y(F.starts, I), le.returnEnd ? 0 : h.length;
}
function pe() {
const I = [];
for (let h = x; h !== _e; h = h.parent)
h.scope && I.unshift(h.scope);
I.forEach((h) => ee.openNode(h));
}
let be = {};
function ve(I, h) {
const P = h && h[0];
if (V += I, P == null)
return G(), 0;
if (be.type === "begin" && h.type === "end" && be.index === h.index && P === "") {
if (V += v.slice(h.index, h.index + 1), !r) {
const F = new Error(`0 width match regex (${b})`);
throw F.languageName = b, F.badRule = be.rule, F;
}
return 1;
}
if (be = h, h.type === "begin")
return ie(h);
if (h.type === "illegal" && !M) {
const F = new Error('Illegal lexeme "' + P + '" for mode "' + (x.scope || "<unnamed>") + '"');
throw F.mode = x, F;
} else if (h.type === "end") {
const F = de(h);
if (F !== ci)
return F;
}
if (h.type === "illegal" && P === "")
return 1;
if (Te > 1e5 && Te > h.index * 3)
throw new Error("potential infinite loop, way more iterations than matches");
return V += P, P.length;
}
const _e = D(b);
if (!_e)
throw Ie(i.replace("{}", b)), new Error('Unknown language: "' + b + '"');
const he = hd(_e);
let Re = "", x = w || he;
const ye = {}, ee = new o.__emitter(o);
pe();
let V = "", fe = 0, ge = 0, Te = 0, Ee = !1;
try {
if (_e