openclaw
Version:
Multi-channel AI gateway with extensible messaging integrations
4,144 lines • 102 kB
JavaScript
import { r as __exportAll$1, s as __toESM } from "./rolldown-runtime-C_OpTf0N.mjs";
import { i as build_exports, n as P, r as S, t as LinkifyIt } from "./build-DFq1Ushr.mjs";
import { t as require_punycode } from "./punycode-Cizsc3oJ.mjs";
import { decodeHTMLStrict } from "entities";
//#region node_modules/.pnpm/mdurl@2.1.0/node_modules/mdurl/lib/decode.mjs
const decodeCache = {};
function getDecodeCache(e) {
let t = decodeCache[e];
if (t) return t;
t = decodeCache[e] = [];
for (let e = 0; e < 128; e++) {
const n = String.fromCharCode(e);
t.push(n);
}
for (let n = 0; n < e.length; n++) {
const r = e.charCodeAt(n);
t[r] = "%" + ("0" + r.toString(16).toUpperCase()).slice(-2);
}
return t;
}
function decode(e, t) {
if (typeof t !== "string") t = decode.defaultChars;
const n = getDecodeCache(t);
return e.replace(/(%[a-f0-9]{2})+/gi, function(e) {
let t = "";
for (let r = 0, i = e.length; r < i; r += 3) {
const a = parseInt(e.slice(r + 1, r + 3), 16);
if (a < 128) {
t += n[a];
continue;
}
if ((a & 224) === 192 && r + 3 < i) {
const n = parseInt(e.slice(r + 4, r + 6), 16);
if ((n & 192) === 128) {
const e = a << 6 & 1984 | n & 63;
if (e < 128) t += "��";
else t += String.fromCharCode(e);
r += 3;
continue;
}
}
if ((a & 240) === 224 && r + 6 < i) {
const n = parseInt(e.slice(r + 4, r + 6), 16);
const i = parseInt(e.slice(r + 7, r + 9), 16);
if ((n & 192) === 128 && (i & 192) === 128) {
const e = a << 12 & 61440 | n << 6 & 4032 | i & 63;
if (e < 2048 || e >= 55296 && e <= 57343) t += "���";
else t += String.fromCharCode(e);
r += 6;
continue;
}
}
if ((a & 248) === 240 && r + 9 < i) {
const n = parseInt(e.slice(r + 4, r + 6), 16);
const i = parseInt(e.slice(r + 7, r + 9), 16);
const o = parseInt(e.slice(r + 10, r + 12), 16);
if ((n & 192) === 128 && (i & 192) === 128 && (o & 192) === 128) {
let e = a << 18 & 1835008 | n << 12 & 258048 | i << 6 & 4032 | o & 63;
if (e < 65536 || e > 1114111) t += "����";
else {
e -= 65536;
t += String.fromCharCode(55296 + (e >> 10), 56320 + (e & 1023));
}
r += 9;
continue;
}
}
t += "�";
}
return t;
});
}
decode.defaultChars = ";/?:@&=+$,#";
decode.componentChars = "";
//#endregion
//#region node_modules/.pnpm/mdurl@2.1.0/node_modules/mdurl/lib/encode.mjs
const encodeCache = {};
function getEncodeCache(e) {
let t = encodeCache[e];
if (t) return t;
t = encodeCache[e] = [];
for (let e = 0; e < 128; e++) {
const n = String.fromCharCode(e);
if (/^[0-9a-z]$/i.test(n)) t.push(n);
else t.push("%" + ("0" + e.toString(16).toUpperCase()).slice(-2));
}
for (let n = 0; n < e.length; n++) t[e.charCodeAt(n)] = e[n];
return t;
}
function encode(e, t, n) {
if (typeof t !== "string") {
n = t;
t = encode.defaultChars;
}
if (typeof n === "undefined") n = true;
const r = getEncodeCache(t);
let i = "";
for (let t = 0, a = e.length; t < a; t++) {
const o = e.charCodeAt(t);
if (n && o === 37 && t + 2 < a) {
if (/^[0-9a-f]{2}$/i.test(e.slice(t + 1, t + 3))) {
i += e.slice(t, t + 3);
t += 2;
continue;
}
}
if (o < 128) {
i += r[o];
continue;
}
if (o >= 55296 && o <= 57343) {
if (o >= 55296 && o <= 56319 && t + 1 < a) {
const n = e.charCodeAt(t + 1);
if (n >= 56320 && n <= 57343) {
i += encodeURIComponent(e[t] + e[t + 1]);
t++;
continue;
}
}
i += "%EF%BF%BD";
continue;
}
i += encodeURIComponent(e[t]);
}
return i;
}
encode.defaultChars = ";/?:@&=+$,-_.!~*'()#";
encode.componentChars = "-_.!~*'()";
//#endregion
//#region node_modules/.pnpm/mdurl@2.1.0/node_modules/mdurl/lib/format.mjs
function format(e) {
let t = "";
t += e.protocol || "";
t += e.slashes ? "//" : "";
t += e.auth ? e.auth + "@" : "";
if (e.hostname && e.hostname.indexOf(":") !== -1) t += "[" + e.hostname + "]";
else t += e.hostname || "";
t += e.port ? ":" + e.port : "";
t += e.pathname || "";
t += e.search || "";
t += e.hash || "";
return t;
}
//#endregion
//#region node_modules/.pnpm/mdurl@2.1.0/node_modules/mdurl/lib/parse.mjs
function Url() {
this.protocol = null;
this.slashes = null;
this.auth = null;
this.port = null;
this.hostname = null;
this.hash = null;
this.search = null;
this.pathname = null;
}
const protocolPattern = /^([a-z0-9.+-]+:)/i;
const portPattern = /:[0-9]*$/;
const simplePathPattern = /^(\/\/?(?!\/)[^\?\s]*)(\?[^\s]*)?$/;
const unwise = [
"{",
"}",
"|",
"\\",
"^",
"`"
].concat([
"<",
">",
"\"",
"`",
" ",
"\r",
"\n",
" "
]);
const autoEscape = ["'"].concat(unwise);
const nonHostChars = [
"%",
"/",
"?",
";",
"#"
].concat(autoEscape);
const hostEndingChars = [
"/",
"?",
"#"
];
const hostnameMaxLen = 255;
const hostnamePartPattern = /^[+a-z0-9A-Z_-]{0,63}$/;
const hostnamePartStart = /^([+a-z0-9A-Z_-]{0,63})(.*)$/;
const hostlessProtocol = {
javascript: true,
"javascript:": true
};
const slashedProtocol = {
http: true,
https: true,
ftp: true,
gopher: true,
file: true,
"http:": true,
"https:": true,
"ftp:": true,
"gopher:": true,
"file:": true
};
function urlParse(e, t) {
if (e && e instanceof Url) return e;
const n = new Url();
n.parse(e, t);
return n;
}
Url.prototype.parse = function(e, t) {
let n, r, i;
let a = e;
a = a.trim();
if (!t && e.split("#").length === 1) {
const e = simplePathPattern.exec(a);
if (e) {
this.pathname = e[1];
if (e[2]) this.search = e[2];
return this;
}
}
let o = protocolPattern.exec(a);
if (o) {
o = o[0];
n = o.toLowerCase();
this.protocol = o;
a = a.substr(o.length);
}
if (t || o || a.match(/^\/\/[^@\/]+@[^@\/]+/)) {
i = a.substr(0, 2) === "//";
if (i && !(o && hostlessProtocol[o])) {
a = a.substr(2);
this.slashes = true;
}
}
if (!hostlessProtocol[o] && (i || o && !slashedProtocol[o])) {
let e = -1;
for (let t = 0; t < hostEndingChars.length; t++) {
r = a.indexOf(hostEndingChars[t]);
if (r !== -1 && (e === -1 || r < e)) e = r;
}
let t, n;
if (e === -1) n = a.lastIndexOf("@");
else n = a.lastIndexOf("@", e);
if (n !== -1) {
t = a.slice(0, n);
a = a.slice(n + 1);
this.auth = t;
}
e = -1;
for (let t = 0; t < nonHostChars.length; t++) {
r = a.indexOf(nonHostChars[t]);
if (r !== -1 && (e === -1 || r < e)) e = r;
}
if (e === -1) e = a.length;
if (a[e - 1] === ":") e--;
const i = a.slice(0, e);
a = a.slice(e);
this.parseHost(i);
this.hostname = this.hostname || "";
const o = this.hostname[0] === "[" && this.hostname[this.hostname.length - 1] === "]";
if (!o) {
const e = this.hostname.split(/\./);
for (let t = 0, n = e.length; t < n; t++) {
const n = e[t];
if (!n) continue;
if (!n.match(hostnamePartPattern)) {
let r = "";
for (let e = 0, t = n.length; e < t; e++) if (n.charCodeAt(e) > 127) r += "x";
else r += n[e];
if (!r.match(hostnamePartPattern)) {
const r = e.slice(0, t);
const i = e.slice(t + 1);
const o = n.match(hostnamePartStart);
if (o) {
r.push(o[1]);
i.unshift(o[2]);
}
if (i.length) a = i.join(".") + a;
this.hostname = r.join(".");
break;
}
}
}
}
if (this.hostname.length > hostnameMaxLen) this.hostname = "";
if (o) this.hostname = this.hostname.substr(1, this.hostname.length - 2);
}
const s = a.indexOf("#");
if (s !== -1) {
this.hash = a.substr(s);
a = a.slice(0, s);
}
const c = a.indexOf("?");
if (c !== -1) {
this.search = a.substr(c);
a = a.slice(0, c);
}
if (a) this.pathname = a;
if (slashedProtocol[n] && this.hostname && !this.pathname) this.pathname = "";
return this;
};
Url.prototype.parseHost = function(e) {
let t = portPattern.exec(e);
if (t) {
t = t[0];
if (t !== ":") this.port = t.substr(1);
e = e.substr(0, e.length - t.length);
}
if (e) this.hostname = e;
};
//#endregion
//#region node_modules/.pnpm/mdurl@2.1.0/node_modules/mdurl/index.mjs
var mdurl_exports = /* @__PURE__ */ __exportAll$1({
decode: () => decode,
encode: () => encode,
format: () => format,
parse: () => urlParse
});
//#endregion
//#region node_modules/.pnpm/markdown-it@15.0.3/node_modules/markdown-it/dist/markdown-it.mjs
/*! markdown-it 15.0.3 https://github.com/markdown-it/markdown-it @license MIT */
var import_punycode = /* @__PURE__ */ __toESM(require_punycode(), 1);
var __defProp = Object.defineProperty;
var __exportAll = (e, t) => {
let n = {};
for (var r in e) __defProp(n, r, {
get: e[r],
enumerable: true
});
if (!t) __defProp(n, Symbol.toStringTag, { value: "Module" });
return n;
};
/**
* Common utility functions exposed through `md.utils` for use by plugins.
*
* @module md.utils
*/
var utils_exports = /* @__PURE__ */ __exportAll({
arrayReplaceAt: () => arrayReplaceAt,
asciiTrim: () => asciiTrim,
callable: () => callable,
escapeHtml: () => escapeHtml,
escapeRE: () => escapeRE,
fromCodePoint: () => fromCodePoint,
isMdAsciiPunct: () => isMdAsciiPunct,
isPunctChar: () => isPunctChar,
isPunctCharCode: () => isPunctCharCode,
isSpace: () => isSpace,
isValidEntityCode: () => isValidEntityCode,
isWhiteSpace: () => isWhiteSpace,
lib: () => lib,
normalizeReference: () => normalizeReference,
unescapeAll: () => unescapeAll,
unescapeMd: () => unescapeMd
});
function callable(e) {
const wrapper = function(...t) {
return Reflect.construct(e, t, new.target && new.target !== wrapper ? new.target : e);
};
Object.defineProperty(wrapper, "name", { value: e.name });
Object.setPrototypeOf(wrapper, e);
wrapper.prototype = e.prototype;
return wrapper;
}
/**
* Returns a copy of a token array with the token at `pos` replaced by
* `newElements`. Used to transform token streams without modifying the
* original array.
*/
function arrayReplaceAt(e, t, n) {
return [].concat(e.slice(0, t), n, e.slice(t + 1));
}
/** Checks whether a code point can be decoded from a numeric HTML entity. */
function isValidEntityCode(e) {
if (e >= 55296 && e <= 57343) return false;
if (e >= 64976 && e <= 65007) return false;
if ((e & 65535) === 65535 || (e & 65535) === 65534) return false;
if (e >= 0 && e <= 8) return false;
if (e === 11) return false;
if (e >= 14 && e <= 31) return false;
if (e >= 127 && e <= 159) return false;
if (e > 1114111) return false;
return true;
}
/**
* Converts a Unicode code point to a string, like `String.fromCodePoint()`,
* but does not throw for invalid input.
*/
function fromCodePoint(e) {
if (e > 65535) {
e -= 65536;
const t = 55296 + (e >> 10);
const n = 56320 + (e & 1023);
return String.fromCharCode(t, n);
}
return String.fromCharCode(e);
}
var UNESCAPE_MD_RE = /\\([!"#$%&'()*+,\-./:;<=>?@[\\\]^_`{|}~])/g;
var UNESCAPE_ALL_RE = new RegExp(`${UNESCAPE_MD_RE.source}|${/&([a-z#][a-z0-9]{1,31});/gi.source}`, "gi");
var DIGITAL_ENTITY_TEST_RE = /^#((?:x[a-f0-9]{1,8}|[0-9]{1,8}))$/i;
function replaceEntityPattern(e, t) {
if (t.charCodeAt(0) === 35 && DIGITAL_ENTITY_TEST_RE.test(t)) {
const n = t[1].toLowerCase() === "x" ? parseInt(t.slice(2), 16) : parseInt(t.slice(1), 10);
if (isValidEntityCode(n)) return fromCodePoint(n);
return e;
}
const n = decodeHTMLStrict(e);
if (n !== e) return n;
return e;
}
/** Decodes Markdown backslash escapes. */
function unescapeMd(e) {
if (e.indexOf("\\") < 0) return e;
return e.replace(UNESCAPE_MD_RE, "$1");
}
/**
* Decodes Markdown backslash escapes and HTML character references in link
* destinations, link titles, and fenced code info strings.
*/
function unescapeAll(e) {
if (e.indexOf("\\") < 0 && e.indexOf("&") < 0) return e;
return e.replace(UNESCAPE_ALL_RE, function(e, t, n) {
if (t) return t;
return replaceEntityPattern(e, n);
});
}
var HTML_ESCAPE_TEST_RE = /[&<>"]/;
var HTML_ESCAPE_REPLACE_RE = /[&<>"]/g;
var HTML_REPLACEMENTS = {
"&": "&",
"<": "<",
">": ">",
"\"": """
};
function replaceUnsafeChar(e) {
return HTML_REPLACEMENTS[e];
}
/** Escapes HTML special characters in a string. */
function escapeHtml(e) {
if (HTML_ESCAPE_TEST_RE.test(e)) return e.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar);
return e;
}
var REGEXP_ESCAPE_RE = /[.?*+^$[\]\\(){}|-]/g;
/** Escapes regular expression metacharacters in a string. */
function escapeRE(e) {
return e.replace(REGEXP_ESCAPE_RE, "\\$&");
}
/** Checks whether a character code is an ASCII space or tab. */
function isSpace(e) {
switch (e) {
case 9:
case 32: return true;
}
return false;
}
/**
* Checks whether a character code is whitespace recognized by Markdown.
*
* Matches the Unicode `Zs` category or `\t`, `\f`, `\v`, `\r`, `\n`.
*/
function isWhiteSpace(e) {
if (e >= 8192 && e <= 8202) return true;
switch (e) {
case 9:
case 10:
case 11:
case 12:
case 13:
case 32:
case 160:
case 5760:
case 8239:
case 8287:
case 12288: return true;
}
return false;
}
/**
* Checks whether a character is Unicode punctuation or a symbol.
*
* Does not support astral characters.
*/
function isPunctChar(e) {
return P.test(e) || S.test(e);
}
/** Checks whether a Unicode code point is punctuation or a symbol. */
function isPunctCharCode(e) {
return isPunctChar(fromCodePoint(e));
}
/**
* Markdown ASCII punctuation characters.
*
* !, ", #, $, %, &, ', (, ), *, +, ,, -, ., /, :, ;, <, =, >, ?, @,
* [, \, ], ^, _, `, {, |, }, or ~
*
* http://spec.commonmark.org/0.15/#ascii-punctuation-character
*
* Don't confuse with Unicode punctuation. It lacks some characters in the
* ASCII range.
*/
function isMdAsciiPunct(e) {
switch (e) {
case 33:
case 34:
case 35:
case 36:
case 37:
case 38:
case 39:
case 40:
case 41:
case 42:
case 43:
case 44:
case 45:
case 46:
case 47:
case 58:
case 59:
case 60:
case 61:
case 62:
case 63:
case 64:
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
case 123:
case 124:
case 125:
case 126: return true;
default: return false;
}
}
/** Normalizes `[reference labels]` for case-insensitive lookup. */
function normalizeReference(e) {
e = e.trim().replace(/\s+/g, " ");
return e.toLowerCase().toUpperCase();
}
function isAsciiTrimmable(e) {
return e === 32 || e === 9 || e === 10 || e === 13;
}
/**
* "Light" `.trim()` for blocks (headings, paragraphs), where Unicode spaces
* should be preserved.
*/
function asciiTrim(e) {
let t = 0;
for (; t < e.length; t++) if (!isAsciiTrimmable(e.charCodeAt(t))) break;
let n = e.length - 1;
for (; n >= t; n--) if (!isAsciiTrimmable(e.charCodeAt(n))) break;
return e.slice(t, n + 1);
}
/**
* Libraries commonly used by markdown-it and its plugins, re-exported to
* reduce duplicate dependencies in browser bundles.
*/
var lib = {
mdurl: mdurl_exports,
ucmicro: build_exports
};
/** Finds the end of a link or image label (`[label]`). */
function parseLinkLabel(e, t, n) {
let r, i, a, o;
const s = e.posMax;
const c = e.pos;
e.pos = t + 1;
r = 1;
while (e.pos < s) {
a = e.src.charCodeAt(e.pos);
if (a === 93) {
r--;
if (r === 0) {
i = true;
break;
}
}
o = e.pos;
e.md.inline.skipToken(e);
if (a === 91) {
if (o === e.pos - 1) r++;
else if (n) {
e.pos = c;
return -1;
}
}
}
let l = -1;
if (i) l = e.pos;
e.pos = c;
return l;
}
/** Parses the destination in `[label](destination "title")`. */
function parseLinkDestination(e, t, n) {
let r;
let i = t;
const a = {
ok: false,
pos: 0,
str: ""
};
if (e.charCodeAt(i) === 60) {
i++;
while (i < n) {
r = e.charCodeAt(i);
if (r === 10) return a;
if (r === 60) return a;
if (r === 62) {
a.pos = i + 1;
a.str = unescapeAll(e.slice(t + 1, i));
a.ok = true;
return a;
}
if (r === 92 && i + 1 < n) {
i += 2;
continue;
}
i++;
}
return a;
}
let o = 0;
while (i < n) {
r = e.charCodeAt(i);
if (r === 32) break;
if (r < 32 || r === 127) break;
if (r === 92 && i + 1 < n) {
if (e.charCodeAt(i + 1) === 32) {
i++;
continue;
}
i += 2;
continue;
}
if (r === 40) {
o++;
if (o > 32) return a;
}
if (r === 41) {
if (o === 0) break;
o--;
}
i++;
}
if (t === i) return a;
if (o !== 0) return a;
a.str = unescapeAll(e.slice(t, i));
a.pos = i;
a.ok = true;
return a;
}
/**
* Parses the optional title in `[label](destination "title")` or
* `[label]: destination "title"`.
*
* `prev_state` continues a reference title on the next source line.
*/
function parseLinkTitle(e, t, n, r) {
let i;
let a = t;
const o = {
ok: false,
can_continue: false,
pos: 0,
str: "",
marker: 0
};
if (r) {
o.str = r.str;
o.marker = r.marker;
} else {
if (a >= n) return o;
let r = e.charCodeAt(a);
if (r !== 34 && r !== 39 && r !== 40) return o;
t++;
a++;
if (r === 40) r = 41;
o.marker = r;
}
while (a < n) {
i = e.charCodeAt(a);
if (i === o.marker) {
o.pos = a + 1;
o.str += unescapeAll(e.slice(t, a));
o.ok = true;
return o;
} else if (i === 40 && o.marker === 41) return o;
else if (i === 92 && a + 1 < n) a++;
a++;
}
o.can_continue = true;
o.str += unescapeAll(e.slice(t, a));
return o;
}
/**
* Functions used to parse links and images, split out of parser rules because
* of their size.
*
* @module md.helpers
*/
var helpers_exports = /* @__PURE__ */ __exportAll({
parseLinkDestination: () => parseLinkDestination,
parseLinkLabel: () => parseLinkLabel,
parseLinkTitle: () => parseLinkTitle
});
function _typeof(e) {
"@babel/helpers - typeof";
return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(e) {
return typeof e;
} : function(e) {
return e && "function" == typeof Symbol && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
}, _typeof(e);
}
function toPrimitive(e, t) {
if ("object" != _typeof(e) || !e) return e;
var n = e[Symbol.toPrimitive];
if (void 0 !== n) {
var r = n.call(e, t || "default");
if ("object" != _typeof(r)) return r;
throw new TypeError("@@toPrimitive must return a primitive value.");
}
return ("string" === t ? String : Number)(e);
}
function toPropertyKey(e) {
var t = toPrimitive(e, "string");
return "symbol" == _typeof(t) ? t : t + "";
}
function _defineProperty(e, t, n) {
return (t = toPropertyKey(t)) in e ? Object.defineProperty(e, t, {
value: n,
enumerable: !0,
configurable: !0,
writable: !0
}) : e[t] = n, e;
}
/**
* Represents one item in the parsed token stream, storing parsed data and
* providing helpers for managing HTML attributes.
*/
var Token = class {
constructor(e, t, n) {
_defineProperty(
this,
/**
* Source map info. Format: `[ line_begin, line_end ]`
*/
"map",
null
);
_defineProperty(
this,
/**
* nesting level, the same as `state.level`
*/
"level",
0
);
_defineProperty(
this,
/**
* An array of child nodes (inline and img tokens)
*/
"children",
null
);
_defineProperty(
this,
/**
* In a case of self-closing tag (code, html, fence, etc.),
* it has contents of this tag.
*/
"content",
""
);
_defineProperty(
this,
/**
* '*' or '_' for emphasis, fence string for fence, etc.
*/
"markup",
""
);
_defineProperty(
this,
/**
* Additional information:
*
* - Info string for "fence" tokens
* - The value "auto" for autolink "link_open" and "link_close" tokens
* - The string value of the item marker for ordered-list "list_item_open" tokens
*/
"info",
""
);
_defineProperty(
this,
/**
* True for block-level tokens, false for inline tokens.
* Used in renderer to calculate line breaks
*/
"block",
false
);
_defineProperty(
this,
/**
* If it's true, ignore this element when rendering. Used for tight lists
* to hide paragraphs.
*/
"hidden",
false
);
this.type = e;
this.tag = t;
this.attrs = null;
this.nesting = n;
this.meta = null;
}
/**
* Search attribute index by name.
*/
attrIndex(e) {
if (!this.attrs) return -1;
const t = this.attrs;
for (let n = 0, r = t.length; n < r; n++) if (t[n][0] === e) return n;
return -1;
}
/**
* Add `[ name, value ]` attribute to list. Init attrs if necessary
*/
attrPush(e) {
if (this.attrs) this.attrs.push(e);
else this.attrs = [e];
}
/**
* Set `name` attribute to `value`. Override old value if exists.
*/
attrSet(e, t) {
const n = this.attrIndex(e);
const r = [e, t];
if (n < 0) this.attrPush(r);
else this.attrs[n] = r;
}
/**
* Get the value of attribute `name`, or null if it does not exist.
*/
attrGet(e) {
const t = this.attrIndex(e);
let n = null;
if (t >= 0) n = this.attrs[t][1];
return n;
}
/**
* Join value to existing attribute via space. Or create new attribute if not
* exists. Useful to operate with token classes.
*/
attrJoin(e, t) {
const n = this.attrIndex(e);
if (n < 0) this.attrPush([e, t]);
else this.attrs[n][1] = `${this.attrs[n][1]} ${t}`;
}
};
/**
* Helper class, used by {@link MarkdownIt.core}, {@link MarkdownIt.block} and
* {@link MarkdownIt.inline} to manage sequences of functions (rules):
*
* - keep rules in defined order
* - assign the name to each rule
* - enable/disable rules
* - add/replace rules
* - allow assign rules to additional named chains (in the same)
* - cacheing lists of active rules
*
* You will not need use this class directly until write plugins. For simple
* rules control use {@link MarkdownIt.disable}, {@link MarkdownIt.enable} and
* {@link MarkdownIt.use}.
*/
var Ruler = class {
constructor() {
_defineProperty(
this,
/** @internal */
"__rules__",
[]
);
_defineProperty(
this,
/** @internal */
"__cache__",
null
);
}
/** @internal */
__find__(e) {
for (let t = 0; t < this.__rules__.length; t++) if (this.__rules__[t].name === e) return t;
return -1;
}
/** @internal */
__compile__() {
const e = /* @__PURE__ */ new Set();
this.__rules__.forEach((t) => {
if (!t.enabled) return;
t.alt.forEach((t) => {
if (t) e.add(t);
});
});
this.__cache__ = Object.create(null);
this.__cache__[""] = [];
this.__rules__.forEach((e) => {
if (e.enabled) this.__cache__[""].push(e.fn);
});
e.forEach((e) => {
this.__cache__[e] = [];
this.__rules__.forEach((t) => {
if (t.enabled && t.alt.indexOf(e) >= 0) this.__cache__[e].push(t.fn);
});
});
}
/**
* Replace rule by name with new function & options. Throws error if name not
* found.
*
* @example Replace existing typographer replacement rule with new one
* ```javascript
* import MarkdownIt from 'markdown-it'
* const md = new MarkdownIt()
*
* md.core.ruler.at('replacements', function replace(state) {
* //...
* });
* ```
*/
at(e, t, n = {}) {
const r = this.__find__(e);
if (r === -1) throw new Error(`Parser rule not found: ${e}`);
this.__rules__[r].fn = t;
this.__rules__[r].alt = n.alt || [];
this.__cache__ = null;
}
/**
* Add new rule to chain before one with given name. See also
* {@link Ruler.after}, {@link Ruler.push}.
*
* @example
* ```javascript
* import MarkdownIt from 'markdown-it'
* const md = new MarkdownIt()
*
* md.block.ruler.before('paragraph', 'my_rule', function replace(state) {
* //...
* });
* ```
*/
before(e, t, n, r = {}) {
const i = this.__find__(e);
if (i === -1) throw new Error(`Parser rule not found: ${e}`);
this.__rules__.splice(i, 0, {
name: t,
enabled: true,
fn: n,
alt: r.alt || []
});
this.__cache__ = null;
}
/**
* Add new rule to chain after one with given name. See also
* {@link Ruler.before}, {@link Ruler.push}.
*
* @example
* ```javascript
* import MarkdownIt from 'markdown-it'
* const md = new MarkdownIt()
*
* md.inline.ruler.after('text', 'my_rule', function replace(state) {
* //...
* });
* ```
*/
after(e, t, n, r = {}) {
const i = this.__find__(e);
if (i === -1) throw new Error(`Parser rule not found: ${e}`);
this.__rules__.splice(i + 1, 0, {
name: t,
enabled: true,
fn: n,
alt: r.alt || []
});
this.__cache__ = null;
}
/**
* Push new rule to the end of chain. See also
* {@link Ruler.before}, {@link Ruler.after}.
*
* @example
* ```javascript
* import MarkdownIt from 'markdown-it'
* const md = new MarkdownIt()
*
* md.core.ruler.push('my_rule', function replace(state) {
* //...
* });
* ```
*/
push(e, t, n = {}) {
this.__rules__.push({
name: e,
enabled: true,
fn: t,
alt: n.alt || []
});
this.__cache__ = null;
}
/**
* Enable rules with given names. If any rule name not found - throw Error.
* Errors can be disabled by second param.
*
* See also {@link Ruler.disable}, {@link Ruler.enableOnly}.
*
* Returns list of found rule names (if no exception happened).
*/
enable(e, t = false) {
if (!Array.isArray(e)) e = [e];
const n = [];
e.forEach((e) => {
const r = this.__find__(e);
if (r < 0) {
if (t) return;
throw new Error(`Rules manager: invalid rule name ${e}`);
}
this.__rules__[r].enabled = true;
n.push(e);
});
this.__cache__ = null;
return n;
}
/**
* Enable rules with given names, and disable everything else. If any rule name
* not found - throw Error. Errors can be disabled by second param.
*
* See also {@link Ruler.disable}, {@link Ruler.enable}.
*/
enableOnly(e, t = false) {
if (!Array.isArray(e)) e = [e];
this.__rules__.forEach((e) => {
e.enabled = false;
});
this.enable(e, t);
}
/**
* Disable rules with given names. If any rule name not found - throw Error.
* Errors can be disabled by second param.
*
* See also {@link Ruler.enable}, {@link Ruler.enableOnly}.
*
* Returns list of found rule names (if no exception happened).
*/
disable(e, t = false) {
if (!Array.isArray(e)) e = [e];
const n = [];
e.forEach((e) => {
const r = this.__find__(e);
if (r < 0) {
if (t) return;
throw new Error(`Rules manager: invalid rule name ${e}`);
}
this.__rules__[r].enabled = false;
n.push(e);
});
this.__cache__ = null;
return n;
}
/**
* Return array of active functions (rules) for given chain name. It analyzes
* rules configuration, compiles caches if not exists and returns result.
*
* Default chain name is `''` (empty string). It can't be skipped. That's
* done intentionally, to keep signature monomorphic for high speed.
*/
getRules(e) {
if (!this.__cache__) this.__compile__();
return this.__cache__[e] || [];
}
};
var default_rules = {};
default_rules.code_inline = function(e, t, n, r, i) {
const a = e[t];
return `<code${i.renderAttrs(a)}>${escapeHtml(a.content)}</code>`;
};
default_rules.code_block = function(e, t, n, r, i) {
const a = e[t];
return `<pre${i.renderAttrs(a)}><code>${escapeHtml(e[t].content)}</code></pre>\n`;
};
default_rules.fence = function(e, t, n, r, i) {
const a = e[t];
const o = a.info ? unescapeAll(a.info).trim() : "";
let s = "";
let c = "";
if (o) {
const e = o.split(/(\s+)/g);
s = e[0];
c = e.slice(2).join("");
}
let l;
if (n.highlight) l = n.highlight(a.content, s, c) || escapeHtml(a.content);
else l = escapeHtml(a.content);
if (l.indexOf("<pre") === 0) return l + "\n";
if (o) {
const e = a.attrIndex("class");
const t = a.attrs ? a.attrs.slice() : [];
if (e < 0) t.push(["class", `${n.langPrefix}${s}`]);
else {
t[e] = [t[e][0], t[e][1]];
t[e][1] += ` ${n.langPrefix}${s}`;
}
const r = { attrs: t };
return `<pre><code${i.renderAttrs(r)}>${l}</code></pre>\n`;
}
return `<pre><code${i.renderAttrs(a)}>${l}</code></pre>\n`;
};
default_rules.image = function(e, t, n, r, i) {
const a = e[t];
a.attrs[a.attrIndex("alt")][1] = i.renderInlineAsText(a.children, n, r);
return i.renderToken(e, t, n);
};
default_rules.hardbreak = function(e, t, n) {
return n.xhtmlOut ? "<br />\n" : "<br>\n";
};
default_rules.softbreak = function(e, t, n) {
return n.breaks ? n.xhtmlOut ? "<br />\n" : "<br>\n" : "\n";
};
default_rules.text = function(e, t) {
return escapeHtml(e[t].content);
};
default_rules.html_block = function(e, t) {
return e[t].content;
};
default_rules.html_inline = function(e, t) {
return e[t].content;
};
/**
* Generates HTML from parsed token stream. Each instance has independent
* copy of rules. Those can be rewritten with ease. Also, you can add new
* rules if you create plugin and adds new token types.
*
* Creates new renderer instance and fills {@link Renderer.rules} with defaults.
*/
var Renderer = class {
constructor() {
_defineProperty(
this,
/**
* Contains render rules for tokens. Can be updated and extended.
*
* See [source code](https://github.com/markdown-it/markdown-it/blob/master/src/renderer.ts)
* for more details and examples.
*
* @example Custom render rules
* ```javascript
* import MarkdownIt from 'markdown-it'
* const md = new MarkdownIt()
*
* md.renderer.rules.strong_open = function () { return '<b>'; };
* md.renderer.rules.strong_close = function () { return '</b>'; };
*
* const result = md.renderInline(...);
* ```
*
* @example Each rule is called as independent static function with fixed signature
* ```javascript
* function my_token_render(tokens, idx, options, env, renderer) {
* // ...
* return renderedHTML;
* }
* ```
*/
"rules",
Object.assign({}, default_rules)
);
}
/**
* Render token attributes to string.
*/
renderAttrs(e) {
let t, n, r;
if (!e.attrs) return "";
r = "";
for (t = 0, n = e.attrs.length; t < n; t++) r += ` ${escapeHtml(e.attrs[t][0])}="${escapeHtml(String(e.attrs[t][1]))}"`;
return r;
}
/**
* Default token renderer. Can be overriden by custom function
* in {@link Renderer.rules}.
*/
renderToken(e, t, n) {
const r = e[t];
let i = "";
if (r.hidden) return "";
let a = t - 1;
while (a >= 0 && e[a].hidden && e[a].nesting === 0) a--;
if (r.block && r.nesting !== -1 && a >= 0 && e[a].hidden && e[a].nesting === -1) i += "\n";
i += (r.nesting === -1 ? "</" : "<") + r.tag;
i += this.renderAttrs(r);
if (r.nesting === 0 && n.xhtmlOut) i += " /";
let o = false;
if (r.block) {
o = true;
if (r.nesting === 1) {
let n = t + 1;
while (n < e.length && e[n].hidden && e[n].nesting === 0) n++;
if (n < e.length) {
const t = e[n];
if (t.type === "inline" || t.hidden) o = false;
else if (t.nesting === -1 && t.tag === r.tag) o = false;
}
}
}
i += o ? ">\n" : ">";
return i;
}
/**
* The same as {@link Renderer.render}, but for single token of `inline` type.
*/
renderInline(e, t, n) {
let r = "";
const i = this.rules;
for (let a = 0, o = e.length; a < o; a++) {
const o = e[a].type;
if (typeof i[o] !== "undefined") r += i[o](e, a, t, n, this);
else r += this.renderToken(e, a, t);
}
return r;
}
/**
* Special kludge for image `alt` attributes to conform CommonMark spec.
* Don't try to use it! Spec requires to show `alt` content with stripped markup,
* instead of simple escaping.
*/
renderInlineAsText(e, t, n) {
let r = "";
for (let i = 0, a = e.length; i < a; i++) switch (e[i].type) {
case "text":
case "code_inline":
r += e[i].content;
break;
case "image":
r += this.renderInlineAsText(e[i].children, t, n);
break;
case "html_inline":
case "html_block":
r += e[i].content;
break;
case "softbreak":
case "hardbreak": r += "\n";
}
return r;
}
/**
* Takes token stream and generates HTML. Probably, you will never need to call
* this method directly.
*/
render(e, t, n) {
let r = "";
const i = this.rules;
for (let a = 0, o = e.length; a < o; a++) {
const o = e[a].type;
if (o === "inline") r += this.renderInline(e[a].children, t, n);
else if (typeof i[o] !== "undefined") r += i[o](e, a, t, n, this);
else r += this.renderToken(e, a, t);
}
return r;
}
};
/** Mutable state passed through the core rules chain. */
var StateCore = class {
constructor(e, t, n) {
_defineProperty(this, "tokens", []);
_defineProperty(this, "inlineMode", false);
_defineProperty(this, "Token", Token);
this.src = e;
this.env = n;
this.md = t;
}
};
var UNNORMALIZED_NEWLINE_RE = /\r\n?/g;
var NULL_RE = /\0/g;
function normalize(e) {
let t;
t = e.src.replace(UNNORMALIZED_NEWLINE_RE, "\n");
t = t.replace(NULL_RE, "�");
e.src = t;
}
function block(e) {
let t;
if (e.inlineMode) {
t = new e.Token("inline", "", 0);
t.content = e.src;
t.map = [0, 1];
t.children = [];
e.tokens.push(t);
} else e.md.block.parse(e.src, e.md, e.env, e.tokens);
}
function strip_references(e) {
const t = e.tokens;
let n = 0;
for (let e = 0; e < t.length; e++) {
if (t[e].type === "reference_definition") continue;
if (e !== n) t[n] = t[e];
n++;
}
if (t.length !== n) t.length = n;
}
function inline(e) {
const t = e.tokens;
for (let n = 0, r = t.length; n < r; n++) {
const r = t[n];
if (r.type === "inline") e.md.inline.parse(r.content, e.md, e.env, r.children);
}
}
function isLinkOpen$1(e) {
return /^<a[>\s]/i.test(e);
}
function isLinkClose$1(e) {
return /^<\/a\s*>/i.test(e);
}
function linkify$1(e) {
const t = e.tokens;
if (!e.md.options.linkify) return;
for (let n = 0, r = t.length; n < r; n++) {
if (t[n].type !== "inline" || !e.md.linkify.test(t[n].content)) continue;
const r = t[n].children;
const i = [];
let a = 0;
for (let t = r.length - 1; t >= 0; t--) {
const n = r[t];
if (n.type === "link_close") {
t--;
while (r[t].level !== n.level && r[t].type !== "link_open") t--;
continue;
}
if (n.type === "html_inline") {
if (isLinkOpen$1(n.content) && a > 0) a--;
if (isLinkClose$1(n.content)) a++;
}
if (a > 0) continue;
if (n.type === "text" && e.md.linkify.test(n.content)) {
const a = n.content;
let o = e.md.linkify.match(a);
const s = [];
let c = n.level;
let l = 0;
if (o.length > 0 && o[0].index === 0 && t > 0 && r[t - 1].type === "text_special") o = o.slice(1);
for (let t = 0; t < o.length; t++) {
const n = o[t].url;
const r = e.md.normalizeLink(n);
if (!e.md.validateLink(r)) continue;
let i = o[t].text;
if (!o[t].schema) i = e.md.normalizeLinkText(`http://${i}`).replace(/^http:\/\//, "");
else if (o[t].schema === "mailto:" && !/^mailto:/i.test(i)) i = e.md.normalizeLinkText(`mailto:${i}`).replace(/^mailto:/, "");
else i = e.md.normalizeLinkText(i);
const u = o[t].index;
if (u > l) {
const t = new e.Token("text", "", 0);
t.content = a.slice(l, u);
t.level = c;
s.push(t);
}
const d = new e.Token("link_open", "a", 1);
d.attrs = [["href", r]];
d.level = c++;
d.markup = "linkify";
d.info = "auto";
s.push(d);
const f = new e.Token("text", "", 0);
f.content = i;
f.level = c;
s.push(f);
const p = new e.Token("link_close", "a", -1);
p.level = --c;
p.markup = "linkify";
p.info = "auto";
s.push(p);
l = o[t].lastIndex;
}
if (l < a.length) {
const t = new e.Token("text", "", 0);
t.content = a.slice(l);
t.level = c;
s.push(t);
}
i.push({
index: t,
nodes: s
});
}
}
if (i.length > 0) {
let e = r.length;
for (const t of i) e += t.nodes.length - 1;
const a = new Array(e);
let o = 0;
let s = 0;
i.reverse();
for (let e = 0; e < r.length; e++) {
const t = i[o];
if ((t === null || t === void 0 ? void 0 : t.index) === e) {
for (const e of t.nodes) a[s++] = e;
o++;
} else a[s++] = r[e];
}
t[n].children = a;
}
}
}
var RARE_RE = /\+-|\.\.|\?\?\?\?|!!!!|,,|--/;
var SCOPED_ABBR_TEST_RE = /\((c|tm|r)\)/i;
var SCOPED_ABBR_RE = /\((c|tm|r)\)/gi;
var SCOPED_ABBR = {
c: "©",
r: "®",
tm: "™"
};
function replaceFn(e, t) {
return SCOPED_ABBR[t.toLowerCase()];
}
function replace_scoped(e) {
let t = 0;
for (let n = e.length - 1; n >= 0; n--) {
const r = e[n];
if (r.type === "text" && !t) r.content = r.content.replace(SCOPED_ABBR_RE, replaceFn);
if (r.type === "link_open" && r.info === "auto") t--;
if (r.type === "link_close" && r.info === "auto") t++;
}
}
function replace_rare(e) {
let t = 0;
for (let n = e.length - 1; n >= 0; n--) {
const r = e[n];
if (r.type === "text" && !t) {
if (RARE_RE.test(r.content)) r.content = r.content.replace(/\+-/g, "±").replace(/\.{2,}/g, "…").replace(/([?!])…/g, "$1..").replace(/([?!]){4,}/g, "$1$1$1").replace(/,{2,}/g, ",").replace(/(^|[^-])---(?=[^-]|$)/gm, "$1—").replace(/(^|\s)--(?=\s|$)/gm, "$1–").replace(/(^|[^-\s])--(?=[^-\s]|$)/gm, "$1–");
}
if (r.type === "link_open" && r.info === "auto") t--;
if (r.type === "link_close" && r.info === "auto") t++;
}
}
function replace(e) {
let t;
if (!e.md.options.typographer) return;
for (t = e.tokens.length - 1; t >= 0; t--) {
if (e.tokens[t].type !== "inline") continue;
if (SCOPED_ABBR_TEST_RE.test(e.tokens[t].content)) replace_scoped(e.tokens[t].children);
if (RARE_RE.test(e.tokens[t].content)) replace_rare(e.tokens[t].children);
}
}
var QUOTE_TEST_RE = /['"]/;
var QUOTE_RE = /['"]/g;
var APOSTROPHE = "’";
var MAX_OPENERS = 1e3;
function truncateStack(e, t, n) {
while (e.length > n) {
const n = e.pop();
if (n.isSingleQuote) t.single = n.prevSameQuoteIdx;
else t.double = n.prevSameQuoteIdx;
}
}
function addReplacement(e, t, n, r) {
if (!e[t]) e[t] = [];
e[t].push({
pos: n,
ch: r
});
}
function applyReplacements(e, t) {
let n = "";
let r = 0;
t.sort((e, t) => e.pos - t.pos);
for (let i = 0; i < t.length; i++) {
const a = t[i];
n += e.slice(r, a.pos) + a.ch;
r = a.pos + 1;
}
return n + e.slice(r);
}
function process_inlines(e, t) {
let n;
const r = [];
const i = {
single: -1,
double: -1
};
const a = {};
for (let o = 0; o < e.length; o++) {
const s = e[o];
const c = e[o].level;
for (n = r.length - 1; n >= 0; n--) if (r[n].level <= c) break;
truncateStack(r, i, n + 1);
if (s.type !== "text") continue;
const l = s.content;
let u = 0;
const d = l.length;
OUTER: while (u < d) {
QUOTE_RE.lastIndex = u;
const s = QUOTE_RE.exec(l);
if (!s) break;
let f = true;
let p = true;
u = s.index + 1;
const m = s[0] === "'";
let h = 32;
if (s.index - 1 >= 0) h = l.charCodeAt(s.index - 1);
else for (n = o - 1; n >= 0; n--) {
if (e[n].type === "softbreak" || e[n].type === "hardbreak") break;
if (!e[n].content) continue;
h = e[n].content.charCodeAt(e[n].content.length - 1);
break;
}
let g = 32;
if (u < d) g = l.charCodeAt(u);
else for (n = o + 1; n < e.length; n++) {
if (e[n].type === "softbreak" || e[n].type === "hardbreak") break;
if (!e[n].content) continue;
g = e[n].content.charCodeAt(0);
break;
}
const _ = isMdAsciiPunct(h) || isPunctCharCode(h);
const v = isMdAsciiPunct(g) || isPunctCharCode(g);
const y = isWhiteSpace(h);
const b = isWhiteSpace(g);
if (b) f = false;
else if (v) {
if (!(y || _)) f = false;
}
if (y) p = false;
else if (_) {
if (!(b || v)) p = false;
}
if (g === 34 && s[0] === "\"") {
if (h >= 48 && h <= 57) p = f = false;
}
if (f && p) {
f = _;
p = v;
}
if (!f && !p) {
if (m) addReplacement(a, o, s.index, APOSTROPHE);
continue;
}
if (p) {
n = m ? i.single : i.double;
if (n >= 0 && r[n].level === c) {
const e = r[n];
let c;
let l;
if (m) {
c = t.md.options.quotes[2];
l = t.md.options.quotes[3];
} else {
c = t.md.options.quotes[0];
l = t.md.options.quotes[1];
}
addReplacement(a, o, s.index, l);
addReplacement(a, e.tokenIdx, e.contentPos, c);
truncateStack(r, i, n);
continue OUTER;
}
}
if (f) {
if (r.length >= MAX_OPENERS) return;
r.push({
tokenIdx: o,
contentPos: s.index,
isSingleQuote: m,
level: c,
prevSameQuoteIdx: m ? i.single : i.double
});
if (m) i.single = r.length - 1;
else i.double = r.length - 1;
} else if (p && m) addReplacement(a, o, s.index, APOSTROPHE);
}
}
Object.keys(a).forEach(function(t) {
const n = Number(t);
e[n].content = applyReplacements(e[n].content, a[t]);
});
}
function smartquotes(e) {
if (!e.md.options.typographer) return;
for (let t = e.tokens.length - 1; t >= 0; t--) {
if (e.tokens[t].type !== "inline" || !QUOTE_TEST_RE.test(e.tokens[t].content)) continue;
process_inlines(e.tokens[t].children, e);
}
}
function join_alt(e) {
let t, n;
const r = e.length;
for (t = 0; t < r; t++) if (e[t].type === "text_special") e[t].type = "text";
for (t = n = 0; t < r; t++) if (e[t].type === "text" && t + 1 < r && e[t + 1].type === "text") e[t + 1].content = e[t].content + e[t + 1].content;
else {
if (t !== n) e[n] = e[t];
n++;
}
if (t !== n) e.length = n;
}
function text_join(e) {
let t, n;
const r = e.tokens;
const i = r.length;
for (let e = 0; e < i; e++) {
if (r[e].type !== "inline") continue;
const i = r[e].children;
const a = i.length;
for (t = 0; t < a; t++) {
if (i[t].type === "text_special") i[t].type = "text";
if (i[t].children) join_alt(i[t].children);
}
for (t = n = 0; t < a; t++) if (i[t].type === "text" && t + 1 < a && i[t + 1].type === "text") i[t + 1].content = i[t].content + i[t + 1].content;
else {
if (t !== n) i[n] = i[t];
n++;
}
if (t !== n) i.length = n;
}
}
var _rules$2 = [
["normalize", normalize],
["block", block],
["strip_references", strip_references],
["inline", inline],
["linkify", linkify$1],
["replacements", replace],
["smartquotes", smartquotes],
["text_join", text_join]
];
/**
* Top-level rules executor. Glues block/inline parsers and does intermediate
* transformations.
*/
var ParserCore = class {
constructor() {
_defineProperty(
this,
/**
* {@link Ruler} instance. Keep configuration of core rules.
*/
"ruler",
new Ruler()
);
_defineProperty(this, "State", StateCore);
for (let e = 0; e < _rules$2.length; e++) this.ruler.push(_rules$2[e][0], _rules$2[e][1]);
}
/**
* Executes core chain rules.
*/
process(e) {
const t = this.ruler.getRules("");
for (let n = 0, r = t.length; n < r; n++) t[n](e);
}
};
/** Mutable state passed to block rules while tokenizing a source document. */
var StateBlock = class {
constructor(e, t, n, r) {
_defineProperty(this, "bMarks", []);
_defineProperty(this, "eMarks", []);
_defineProperty(this, "tShift", []);
_defineProperty(this, "sCount", []);
_defineProperty(this, "bsCount", []);
_defineProperty(this, "blkIndent", 0);
_defineProperty(this, "line", 0);
_defineProperty(this, "lineMax", 0);
_defineProperty(this, "tight", false);
_defineProperty(this, "listIndent", -1);
_defineProperty(this, "parentType", "root");
_defineProperty(this, "level", 0);
_defineProperty(this, "Token", Token);
this.src = e;
this.md = t;
this.env = n;
this.tokens = r;
const i = this.src;
for (let e = 0, t = 0, n = 0, r = 0, a = i.length, o = false; t < a; t++) {
const s = i.charCodeAt(t);
if (!o) {
if (isSpace(s)) {
n++;
if (s === 9) r += 4 - r % 4;
else r++;
continue;
} else o = true;
}
if (s === 10 || t === a - 1) {
if (s !== 10) t++;
this.bMarks.push(e);
this.eMarks.push(t);
this.tShift.push(n);
this.sCount.push(r);
this.bsCount.push(0);
o = false;
n = 0;
r = 0;
e = t + 1;
}
}
this.bMarks.push(i.length);
this.eMarks.push(i.length);
this.tShift.push(0);
this.sCount.push(0);
this.bsCount.push(0);
this.lineMax = this.bMarks.length - 1;
}
push(e, t, n) {
const r = new Token(e, t, n);
r.block = true;
if (n < 0) this.level--;
r.level = this.level;
if (n > 0) this.level++;
this.tokens.push(r);
return r;
}
isEmpty(e) {
return this.bMarks[e] + this.tShift[e] >= this.eMarks[e];
}
skipEmptyLines(e) {
for (let t = this.lineMax; e < t; e++) if (this.bMarks[e] + this.tShift[e] < this.eMarks[e]) break;
return e;
}
skipSpaces(e) {
for (let t = this.src.length; e < t; e++) if (!isSpace(this.src.charCodeAt(e))) break;
return e;
}
skipSpacesBack(e, t) {
if (e <= t) return e;
while (e > t) if (!isSpace(this.src.charCodeAt(--e))) return e + 1;
return e;
}
skipChars(e, t) {
for (let n = this.src.length; e < n; e++) if (this.src.charCodeAt(e) !== t) break;
return e;
}
skipCharsBack(e, t, n) {
if (e <= n) return e;
while (e > n) if (t !== this.src.charCodeAt(--e)) return e + 1;
return e;
}
getLines(e, t, n, r) {
if (e >= t) return "";
const i = new Array(t - e);
for (let a = 0, o = e; o < t; o++, a++) {
let e = 0;
const s = this.bMarks[o];
let c = s;
let l;
if (o + 1 < t || r) l = this.eMarks[o] + 1;
else l = this.eMarks[o];
while (c < l && e < n) {
const t = this.src.charCodeAt(c);
if (isSpace(t)) {
if (t === 9) e += 4 - (e + this.bsCount[o]) % 4;
else e++;
} else if (c - s < this.tShift[o]) e++;
else break;
c++;
}
if (e > n) i[a] = new Array(e - n + 1).join(" ") + this.src.slice(c, l);
else i[a] = this.src.slice(c, l);
}
return i.join("");
}
};
var MAX_AUTOCOMPLETED_CELLS = 65536;
function getLine(e, t) {
const n = e.bMarks[t] + e.tShift[t];
const r = e.eMarks[t];
return e.src.slice(n, r);
}
function escapedSplit(e) {
const t = [];
const n = e.length;
let r = 0;
let i = e.charCodeAt(r);
let a = false;
let o = 0;
let s = "";
while (r < n) {
if (i === 124) {
if (!a) {
t.push(s + e.substring(o, r));
s = "";
o = r + 1;
} else {
s += e.substring(o, r - 1);
o = r;
}
}
a = i === 92;
r++;
i = e.charCodeAt(r);
}
t.push(s + e.substring(o));
return t;
}
function table(e, t, n, r) {
if (t + 2 > n) return false;
let i = t + 1;
if (e.sCount[i] < e.blkIndent) return false;
if (e.sCount[i] - e.blkIndent >= 4) return false;
let a = e.bMarks[i] + e.tShift[i];
if (a >= e.eMarks[i]) return false;
const o = e.src.charCodeAt(a++);
if (o !== 124 && o !== 45 && o !== 58) return false;
if (a >= e.eMarks[i]) return false;
const s = e.src.charCodeAt(a++);
if (s !== 124 && s !== 45 && s !== 58 && !isSpace(s)) return false;
if (o === 45 && isSpace(s)) return false;
while (a < e.eMarks[i]) {
const t = e.src.charCodeAt(a);
if (t !== 124 && t !== 45 && t !== 58 && !isSpace(t)) return false;
a++;
}
let c = getLine(e, t + 1);
let l = c.split("|");
const u = [];
for (let e = 0; e < l.length; e++) {
const t = l[e].trim();
if (!t) {
if (e === 0 || e === l.length - 1) continue;
else return false;
}
if (!/^:?-+:?$/.test(t)) return false;
if (t.charCodeAt(t.length - 1) === 58) u.push(t.charCodeAt(0) === 58 ? "center" : "right");
else if (t.charCodeAt(0) === 58) u.push("left");
else u.push("");
}
c = getLine(e, t).trim();
if (c.indexOf("|") === -1) return false;
if (e.sCount[t] - e.blkIndent >= 4) return false;
l = escapedSplit(c);
if (l.length && l[0] === "") l.shift();
if (l.length && l[l.length - 1] === "") l.pop();
const d = l.length;
if (d === 0 || d !== u.length) return false;
if (r) return true;
const f = e.parentType;
e.parentType = "table";
const p = e.md.block.ruler.getRules("blockquote");
const m = e.push("table_open", "table", 1);
const h = [t, 0];
m.map = h;
const g = e.push("thead_open", "thead", 1);
g.map = [t, t + 1];
const _ = e.push("tr_open", "tr", 1);
_.map = [t, t + 1];
for (let t = 0; t < l.length; t++) {
const n = e.push("th_open", "th", 1);
if (u[t]) n.attrs = [["style", `text-align:${u[t]}`]];
const r = e.push("inline", "", 0);
r.content = l[t].trim();
r.children = [];
e.push("th_close", "th", -1);
}
e.push("tr_close", "tr", -1);
e.push("thead_close", "thead", -1);
let v;
let y = 0;
for (i = t + 2; i < n; i++) {
if (e.sCount[i] < e.blkIndent) break;
let r = false;
for (let t = 0, a = p.length; t < a; t++) if (p[t](e, i, n, true)) {
r = true;
break;
}
if (r) break;
c = getLine(e, i).trim();
if (!c) break;
if (e.sCount[i] - e.blkIndent >= 4) break;
l = escapedSplit(c);
if (l.length && l[0] === "") l.shift();
if (l.length && l[l.length - 1] === "") l.pop();
y += d - l.length;
if (y > MAX_AUTOCOMPLETED_CELLS) break;
if (i === t + 2) {
const n = e.push("tbody_open", "tbody", 1);
n.map = v = [t + 2, 0];
}
const a = e.push("tr_open", "tr", 1);
a.map = [i, i + 1];
for (let t = 0; t < d; t++) {
const n = e.push("td_open", "td", 1);
if (u[t]) n.attrs = [["style", `text-align:${u[t]}`]];
const r = e.push("inline", "", 0);
r.content = l[t] ? l[t].trim() : "";
r.children = [];
e.push("td_close", "td", -1);
}
e.push("tr_close", "tr", -1);
}
if (v) {
e.push("tbody_close", "tbody", -1);
v[1] = i;
}
e.push("table_close", "table", -1);
h[1] = i;
e.parentType = f;
e.line = i;
return true;
}
function code(e, t, n) {
if (e.sCount[t] - e.blkIndent < 4) return false;
let r = t + 1;
let i = r;
while (r < n) {
if (e.isEmpty(r)) {
r++;
continue;
}
if (e.sCount[r] - e.blkIndent >= 4) {
r++;
i = r;
continue;
}
break;
}
e.line = i;
const a = e.push("code_block", "code", 0);
a.content = e.getLines(t, i, 4 + e.blkIndent, false) + "\n";
a.map = [t, e.line];
return true;
}
function fence(e, t, n, r) {
let i = e.bMarks[t] + e.tShift[t];
let a = e.eMarks[t];
if (e.sCount[t] - e.blkIndent >= 4) return false;
if (i + 3 > a) return false;
const o = e.src.charCodeAt(i);
if (o !== 126 && o !== 96) return false;
let s = i;
i = e.skipChars(i, o);
let c = i - s;
if (c < 3) return false;
const l = e.src.slice(s, i);
const u = e.src.slice(i, a);
if (o === 96) {
if (u.indexOf(String.fromCharCode(o)) >= 0) return false;
}
if (r) return true;
let d = t;
let f = false;
for (;;) {
d++;
if (d >= n) break;
i = s = e.bMarks[d] + e.tShift[d];
a = e.eMarks[d];
if (i < a && e.sCount[d] < e.blkIndent) break;
if (e.src.charCodeAt(i) !== o) continue;
if (e.sCount[d] - e.blkIndent >= 4) continue;
i = e.skipChars(i, o);
if (i - s < c) continue;
i = e.skipSpaces(i);
if (i < a) continue;
f = true;
break;
}
c = e.sCount[t];
e.line = d + (f ? 1 : 0);
const p = e.push("fence", "code", 0);
p.info = u;
p.content = e.getLines(t + 1, d, c, true);
p.markup = l;
p.map = [t, e.line];
return true;
}
function blockquote(e, t, n, r) {
let i = e.bMarks[t] + e.tShift[t];
let a = e.eMarks[t];
const o = e.lineMax;
if (e.sCount[t] - e.blkIndent >= 4) return false;
if (e.src.charCodeAt(i) !== 62) return false;
if (r) return true;
const s = [];
const c = [];
const l = [];
const u = [];
const d = e.md.block.ruler.getRules("blockquote");
const f = e.parentType;
e.parentType = "blockquote";
let p = false;
let m;
for (m = t; m < n; m++) {
const t = e.sCount[m] < e.blkIndent;
i = e.bMarks[m] + e.tShift[m];
a = e.eMarks[m];
if (i >= a) break;
if (e.src.charCodeAt(i++) === 62 && !t) {
let t = e.sCount[m] + 1;
let n;
let r;
if (e.src.charCodeAt(i) === 32) {
i++;
t++;
r = false;
n = true;
} else if (e.src.charCodeAt(i) === 9) {
n = true;
if ((e.bsCount[m] + t) % 4 === 3) {
i++;
t++;
r = false;
} else r = true;
} else n = false;
let o = t;
s.push(e.bMarks[m]);
e.bMarks[m] = i;
while (i < a) {
const t = e.src.charCodeAt(i);
if (isSpace(t)) {
if (t === 9) o += 4 - (o + e.bsCount[m] + (r ? 1 : 0)) % 4;
else o++;
} else break;
i++;
}
p = i >= a;
c.push(e.bsCount[m]);
e.bsCount[m] = e.sCount[m] + 1 + (n ? 1 : 0);
l.push(e.sCount[m]);
e.sCount[m] = o - t;
u.push(e.tShift[m]);
e.tShift[m] = i - e.bMarks[m];
continue;
}
if (p) break;
let r = false;
for (let t = 0, i = d.length; t < i; t++) if (d[t](e, m, n, true)) {
r = true;
break;
}
if (r) {
e.lineMax = m;
if (e.blkIndent !== 0) {
s.push(e.bMarks[m]);
c.push(e.bsCount[m]);
u.push(e.tShift[m]);
l.push(e.sCount[m]);
e.sCount[m] -= e.blkIndent;
}
break;
}
s.push(e.bMarks[m]);
c.push(e.bsCount[m]);
u.push(e.tShift[m]);
l.push(e.sCount[m]);
e.sCount[m] = -1;
}
const h = e.blkIndent;
e.blkIndent = 0;
const g = e.push("blockquote_open", "blockquote", 1);
g.markup = ">";
const _ = [t, 0];
g.map = _;
e.md.block.tokenize(e, t, m);
const v = e.push("blockquote_close", "blockquote", -1);
v.markup = ">";
e.lineMax = o;
e.parentType = f;
_[1] = e.line;
for (let n = 0; n < u.length; n++) {
e.bMarks[n + t] = s[n];
e.tShift[n + t] = u[n];
e.sCount[n + t] = l[n];
e.bsCount[n + t] = c[n];
}
e.blkIndent = h;
return true;
}
function hr(e, t, n, r) {
const i = e.eMarks[t];
if (e.sCount[t] - e.blkIndent >= 4) return false;
let a = e.bMarks[t] + e.tShift[t];
const o = e.src.charCodeAt(a++);
if (o !== 42 && o !== 45 && o !== 95) return false;
let s = 1;
while (a < i) {
const t = e.src.charCodeAt(a++);
if (t !== o && !isSpace(t)) return false;
if (t === o) s++;
}
if (s < 3) return false;
if (r) return true;
e.line = t + 1;
const c = e.push("hr", "hr", 0);
c.map = [t, e.line];
c.markup = Array(s + 1).join(String.fromCharCode(o));
return true;
}
function skipBulletListMarker(e, t) {
const n = e.eMarks[t];
let r = e.bMarks[t] + e.tShift[t];
const i = e.src.charCodeAt(r++);
if (i !== 42 && i !== 45 && i !== 43) return -1;
if (r < n) {
if (!isSpace(e.src.charCodeAt(r))) return -1;
}
return r;
}
function skipOrderedListMarker(e, t) {
const n = e.bMarks[t] + e.tShift[t];
const r = e.eMarks[t];
let i = n;
if (i + 1 >= r) return -1;
let a = e.src.charCodeAt(i++);
if (a < 48 || a > 57) return -1;
for (;;) {
if (i >= r) return -1;
a = e.src.charCodeAt(i++);
if (a >= 48 && a <= 57) {
if (i - n >= 10) return -1;
continue;
}
if (a === 41 || a === 46) break;
return -1;
}
if (i < r) {
a = e.src.charCodeAt(i);
if (!isSpace(a)) return -1;
}
return i;
}
function markTightParagraphs(e, t) {
const n = e.level + 2;
for (let r = t + 2, i = e.tokens.length - 2; r < i; r++) if (e.tokens[r].level === n && e.tokens[r].type === "paragraph_open") {
e.tokens[r + 2].hidden = true;
e.tokens[r].hidden = true;
r += 2;
}
}
function list(e, t, n, r) {
let i, a, o, s;
let c = t;
let l = true;
if (e.sCount[c] - e.blkIndent >= 4) return false;
if (e.listIndent >= 0 && e.sCount[c] - e.listIndent >= 4 && e.sCount[c] < e.blkIndent) return false;
let u = false;
if (r && e.parentType === "paragraph") {
if (e.sCount[c] >= e.blkIndent) u = true;
}
let d;
let f;
let p;
if ((p = skipOrderedListMarker(e, c)) >= 0) {
d = true;
o = e.bMarks[c] + e.tShift[c];
f = Number(e.src.slice(o, p - 1));
if (u && f !== 1) return false;
} else if ((p = skipBulletListMarker(e, c)) >= 0) d = false;
else return false;
if (u) {
if (e.skipSpaces(p) >= e.eMarks[c]) return false;
}
if (r) return true;
const m = e.src.charCodeAt(p - 1);
const h = e.tokens.length;
if (d) {
s = e.push("ordered_list_open", "ol", 1);
if (f !== 1) s.attrs = [["start", f]];
} else s = e.push("bullet_list_open", "ul", 1);
const g = [c, 0];
s.map = g;
s.markup = String.fromCharCode(m);
let _ = false;
const v = e.md.block.ruler.getRules("list");
const y = e.parentType;
e.parentType = "list";
while (c < n) {
a = p;
i = e.eMarks[c];
const t = e.sCount[c] + p - (e.bMarks[c] + e.tShift[c]);
let r = t;
while (a < i) {
const t = e.src.charCodeAt(a);
if (t === 9) r += 4 - (r + e.bsCount[c]) % 4;
else if (t === 32) r++;
else break;
a++;
}
const u = a;
let f;
if (u >= i) f = 1;
else f = r - t;
if (f > 4) f = 1;
const h = t + f;
s = e.push("list_item_open", "li", 1);
s.markup = String.fromCharCode(m);
const g = [c, 0];
s.map = g;
if (d) s.info = e.src.slice(o, p - 1);
const y = e.tight;
const b = e.tShift[c];
const x = e.sCount[c];
const C = e.listIndent;
e.listIndent = e.blkIndent;
e.blkIndent = h;
e.tight = true;
e.tShift[c] = u - e.bMarks[c];
e.sCount[c] = r;
if (u >= i && e.isEmpty(c + 1)) e.line = Math.min(e.line + 2, n);
else e.md.block.tokenize(e, c, n);
if (!e.tight || _) l = false;
_ = e.line - c > 1 && e.isEmpty(e.line - 1);
e.blkIndent = e.listIndent;
e.listIndent = C;
e.tShift[c] = b;
e.sCount[c] = x;
e.tight = y;
s = e.push("list_item_close", "li", -1);
s.markup = String.fromCharCode(m);
c = e.line;
g[1] = c;
if (c >= n) break;
if (e.sCount[c] < e.blkIndent) break;
if (e.sCount[c] - e.blkIndent >= 4) break;
let w = false;
for (let t = 0, r = v.length; t < r; t++) if (v[t](e, c, n, true)) {
w = true;
break;
}
if (w) break;
if (d) {
p = skipOrderedListMarker(e, c);
if (p < 0) break;
o = e.bMarks[c] + e.tShift[c];
} else {
p = skipBulletListMarker(e, c);
if (p < 0) break;
}
if (m !== e.src.charCodeAt(p - 1)) break;
}
if (d) s = e.push("ordered_list_close", "ol", -1);
else s = e.push("bullet_list_close", "ul", -1);
s.markup = String.fromCharCode(m);
g[1] = c;
e.line = c;
e.parentType = y;
if (l) markTightParagraphs(e, h);
return true;
}
var MAX_LABEL_LENGTH = 999;
function countCodePoints(e) {
let t = e.length;
for (let n = 0; n < e.length - 1; n++) {
const r = e.charCodeAt(n);
if (r < 55296 || r > 56319) continue;
const i = e.charCodeAt(n + 1);
if (i >= 56320 && i <= 57343) {
t--;
n++;
}
}
return t;
}
function lineEnd(e, t) {
return Math.min(e.eMarks[t] + 1, e.src.length);
}
function getNextLinePos(e, t) {
const n = e.lineMax;
if (t >= n || e.isEmpty(t)) return -1;
let r = false;
if (e.sCount[t] - e.blkIndent > 3) r = true;
if (e.sCount[t] < 0) r = true;
if (!r) {
const r = e.md.block.ruler.getRules("reference");
const i = e.parentType;
e.parentType = "reference";
let a = false;
for (let i = 0, o = r.length; i < o; i++) if (r[i](e, t, n, true)) {
a = true;
break;
}
e.parentType = i;
if (a) return -1;
}
return e.bMarks[t] + e.tShift[t];
}
function reference(e, t, n, r) {
const i = e.src;
let a = e.bMarks[t] + e.tShift[t];
let o = t + 1;
if (e.sCount[t] - e.blkIndent >= 4) return false;
if (i.charCodeAt(a) !== 91) return false;
let s = lineEnd(e, t);
let c = "";
let l = -1;
let u = ++a;
while (a < s) {
if (c.length + a - u > MAX_LABEL_LENGTH * 2) return false;
let t = i.charCodeAt(a);
if (t === 91) return false;
if (t === 93) {
l = a;
break;
}
if (t === 92) t = i.charCodeAt(++a);
if (t === 10 && a < s) {
const t = getNextLinePos(e, o);
if (t < 0) return false;
c += i.slice(u, s);
a = u = t;
s = lineEnd(e, o++);
continue;
}
a++;
}
if (l < 0 || i.charCodeAt(l + 1) !== 58) return false;
c += i.slice(u, l);
if (c.length > MAX_LABEL_LENGTH && countCodePoints(c) > MAX_LABEL_LENGTH) return false;
a = l + 2;
while (a < s) {
const t = i.charCodeAt(a);
if (t === 10) {
const t = getNextLinePos(e, o);
if (t < 0) break;
a = t;
s = lineEnd(e, o++);
} else if (isSpace(t)) a++;
else break;
}
const d = e.md.helpers.parseLinkDestination(i, a, s);
if (!d.ok) return false;
const f = e.md.normalizeLink(d.str);
if (!e.md.validateLink(f)) return false;
a = d.pos;
const p = a;
const m = s;
const h = o;
while (a < s) {
const t = i.charCodeAt(a);
if (t === 10) {
const t = getNextLinePos(e, o);
if (t < 0) break;
a = t;
s = lineEnd(e, o++);
} else if (isSpace(t)) a++;
else break;
}
const g = a;
let _ = e.md.helpers.parseLinkTitle(i, a, s);
while (_.can_continue) {
const t = getNextLinePos(e, o);
if (t < 0) break;
a = t;
s = lineEnd(e, o++);
_ = e.md.helpers.parseLinkTitle(i, a, s, _);
}
let v;
if (g !== p && _.ok) {
v = _.str;
a = _.pos;
} else {
v = "";
a = p;
s = m;
o = h;
}
while (a < s) {
if (!isSpace(i.charCodeAt(a))) break;
a++;
}
if (a < s && i.charCodeAt(a) !== 10) {
if (v) {
v = "";
a = p;
s = m;
o = h;
while (a < s) {
if (!isSpace(i.charCodeAt(a))) break;
a++;
}
}
}
if (a < s && i.charCodeAt(a) !== 10) return false;
const y = normalizeReference(c);
if (!y) return false;
/* istanbul ignore if */
if (r) return true;
if (typeof e.env.references === "undefined") e.env.references = {};
if (typeof e.env.references[y] === "undefined") e.env.references[y] = {
title: v,
href: f
};
const b = e.push("reference_definition", "", 0);
b.map = [t, o];
b.hidden = true;
const x = Object.create(null);
x.label = y;
b.meta = x;
e.line = o;
return true;
}
var html_blocks_default = [
"address",
"article",
"aside",
"base",
"basefont",
"blockquote",
"body",
"caption",
"center",
"col",
"colgroup",
"dd",
"details",
"dialog",
"dir",
"div",
"dl",
"dt",
"fieldset",
"figcaption",
"figure",
"footer",
"form",
"frame",
"frameset",
"h1",
"h2",
"h3",
"h4",
"h5",
"h6",
"head",
"header",
"hr",
"html",
"iframe",
"legend",
"li",
"link",
"main",
"menu",
"menuitem",
"nav",
"noframes",
"ol",
"optgroup",
"option",
"p",
"param",
"search",
"section",
"summary",
"table",
"tbody",
"td",
"tfoot",
"th",
"thead",
"title",
"tr",
"track",
"ul"
];
var open_tag = `<[A-Za-z][A-Za-z0-9\\-]*(?:\\s+[a-zA-Z_:][a-zA-Z0-9:._-]*(?:\\s*=\\s*(?:[^"'=<>\`\\x00-\\x20]+|'[^']*'|"[^"]*"))?)*\\s*\\/?>`;
var close_tag = "<\\/[A-Za-z][A-Za-z0-9\\-]*\\s*>";
new RegExp(`^(?:${open_tag}|${close_tag}|<!---?>|<!--(?:[^-]|-[^-]|--[^>])*-->|<[?][\\s\\S]*?[?]>|<![A-Za-z][^>]*>|<!\\[CDATA\\[[\\s\\S]*?\\]\\]>)`);
var HTML_OPEN_CLOSE_TAG_RE = new RegExp(`^(?:${open_tag}|${close_tag})`);
var HTML_SEQUENCES = [
[
/^<(script|pre|style|textarea)(?=(\s|>|$))/i,
/<\/(script|pre|style|textarea)>/i,
true
],
[
/^<!--/,
/-->/,
true
],
[
/^<\?/,
/\?>/,
true
],
[
/^<![A-Za-z]/,
/>/,
true
],
[
/^<!\[CDATA\[/,
/\]\]>/,
true
],
[
new RegExp(`^</?(${html_blocks_default.join("|")})(?=(\\s|/?>|$))`, "i"),
/^$/,
true
],
[
new RegExp(`${HTML_OPEN_CLOSE_TAG_RE.source}\\s*$`),
/^$/,
false
]
];
function html_block(e, t, n, r) {
let i = e.bMarks[t] + e.tShift[t];
let a = e.eMarks[t];
if (e.sCount[t] - e.blkIndent >= 4) return false;
if (!e.md.options.html) return false;
if (e.src.charCodeAt(i) !== 60) return false;
let o = e.src.slice(i, a);
let s = 0;
for (; s < HTML_SEQUENCES.length; s++) if (HTML_SEQUENCES[s][0].test(o)) break;
if (s === HTML_SEQUENCES.length) return false;
if (r) return HTML_SEQUENCES[s][2];
let c = t + 1;
const l = HTML_SEQUENCES[s][1].test("");
if (!HTML_SEQUENCES[s][1].test(o)) for (; c < n; c++) {
if (e.sCount[c] < e.blkIndent) {
if (l || !e.isEmpty(c)) break;
}
i = e.bMarks[c] + e.tShift[c];
a = e.eMarks[c];
o = e.src.slice(i, a);
if (HTML_SEQUENCES[s][1].test(o)) {
if (o.length !== 0) c++;
break;
}
}
e.line = c;
const u = e.push("html_block", "", 0);
u.map = [t, c];
u.content = e.getLines(t, c, e.blkIndent, true);
return true;
}
function heading(e, t, n, r) {
let i = e.bMarks[t] + e.tShift[t];
let a = e.eMarks[t];
if (e.sCount[t] - e.blkIndent >= 4) return false;
let o = e.src.charCodeAt(i);
if (o !== 35 || i >= a) return false;
let s = 1;
o = e.src.charCodeAt(++i);
while (o === 35 && i < a && s <= 6) {
s++;
o = e.src.charCodeAt(++i);
}
if (s > 6 || i < a && !isSpace(o)) return false;
if (r) return true;
a = e.skipSpacesBack(a, i);
const c = e.skipCharsBack(a, 35, i);
if (c > i && isSpace(e.src.charCodeAt(c - 1))) a = c;
e.line = t + 1;
const l = e.push("heading_open", `h${s}`, 1);
l.markup = "########".slice(0, s);
l.map = [t, e.line];
const u = e.push("inline", "", 0);
u.content = asciiTrim(e.src.slice(i, a));
u.map = [t, e.line];
u.children = [];
const d = e.push("heading_close", `h${s}`, -1);
d.markup = "########".slice(0, s);
return true;
}
function lheading(e, t, n) {
const r = e.md.block.ruler.getRules("paragraph");
if (e.sCount[t] - e.blkIndent >= 4) return false;
const i = e.parentType;
e.parentType = "paragraph";
let a = 0;
let o;
let s = t + 1;
for (; s < n && !e.isEmpty(s); s++) {
if (e.sCount[s] - e.blkIndent > 3) continue;
if (e.sCount[s] >= e.blkIndent) {
let t = e.bMarks[s] + e.tShift[s];
const n = e.eMarks[s];
if (t < n) {
o = e.src.charCodeAt(t);
if (o === 45 || o === 61) {
t = e.skipChars(t, o);
t = e.skipSpaces(t);
if (t >= n) {
a = o === 61 ? 1 : 2;
break;
}
}
}
}
if (e.sCount[s] < 0) continue;
let t = false;
for (let i = 0, a = r.length; i < a; i++) if (r[i](e, s, n, true)) {
t = true;
break;
}
if (t) break;
}
if (!a) {
e.parentType = i;
return false;
}
const c = asciiTrim(e.getLines(t, s, e.blkIndent, false));
e.line = s + 1;
const l = e.push("heading_open", `h${a}`, 1);
l.markup = String.fromCharCode(o);
l.map = [t, e.line];
const u = e.push("inline", "", 0);
u.content = c;
u.map = [t, e.line - 1];
u.children = [];
const d = e.push("heading_close", `h${a}`, -1);
d.markup = String.fromCharCode(o);
e.parentType = i;
return true;
}
function paragraph(e, t, n) {
const r = e.md.block.ruler.getRules("paragraph");
const i = e.parentType;
let a = t + 1;
e.parentType = "paragraph";
for (; a < n && !e.isEmpty(a); a++) {
if (e.sCount[a] - e.blkIndent > 3) continue;
if (e.sCount[a] < 0) continue;
let t = false;
for (let i = 0, o = r.length; i < o; i++) if (r[i](e, a, n, true)) {
t = true;
break;
}
if (t) break;
}
const o = asciiTrim(e.getLines(t, a, e.blkIndent, false));
e.line = a;
const s = e.push("paragraph_open", "p", 1);
s.map = [t, e.line];
const c = e.push("inline", "", 0);
c.content = o;
c.map = [t, e.line];
c.children = [];
e.push("paragraph_close", "p", -1);
e.parentType = i;
return true;
}
var _rules$1 = [
[
"table",
table,
["paragraph", "reference"]
],
["code", code],
[
"fence",
fence,
[
"paragraph",
"reference",
"blockquote",
"list"
]
],
[
"blockquote",
blockquote,
[
"paragraph",
"reference",
"blockquote",
"list"
]
],
[
"hr",
hr,
[
"paragraph",
"reference",
"blockquote",
"list"
]
],
[
"list",
list,
[
"paragraph",
"reference",
"blockquote"
]
],
["reference", reference],
[
"html_block",
html_block,
[
"paragraph",
"reference",
"blockquote"
]
],
[
"heading",
heading,
[
"paragraph",
"reference",
"blockquote"
]
],
["lheading", lheading],
["paragraph", paragraph]
];
/**
* Block-level tokenizer.
*/
var ParserBlock = class {
constructor() {
_defineProperty(
this,
/**
* {@link Ruler} instance. Keep configuration of block rules.
*/
"ruler",
new Ruler()
);
_defineProperty(this, "State", StateBlock);
for (let e = 0; e < _rules$1.length; e++) this.ruler.push(_rules$1[e][0], _rules$1[e][1], { alt: (_rules$1[e][2] || []).slice() });
}
tokenize(e, t, n) {
const r = this.ruler.getRules("");
const i = r.length;
const a = e.md.options.maxNesting;
let o = t;
let s = false;
while (o < n) {
e.line = o = e.skipEmptyLines(o);
if (o >= n) break;
if (e.sCount[o] < e.blkIndent) break;
if (e.level >= a) {
e.line = n;
break;
}
const t = e.line;
let c = false;
for (let a = 0; a < i; a++) {
c = r[a](e, o, n, false);
if (c) {
if (t >= e.line) throw new Error("block rule didn't increment state.line");
break;
}
}
if (!c) throw new Error("none of the block rules matched");
e.tight = !s;
if (e.isEmpty(e.line - 1)) s = true;
o = e.line;
if (o < n && e.isEmpty(o)) {
s = true;
o++;
e.line = o;
}
}
}
/**
* Process input string and push block tokens into `outTokens`
*/
parse(e, t, n, r) {
if (!e) return;
const i = new this.State(e, t, n, r);
this.tokenize(i, i.line, i.lineMax);
}
};
/** Mutable state passed to inline rules while tokenizing inline content. */
var StateInline = class {
constructor(e, t, n, r) {
_defineProperty(this, "pos", 0);
_defineProperty(this, "level", 0);
_defineProperty(this, "pending", "");
_defineProperty(this, "pendingLevel", 0);
_defineProperty(this, "cache", {});
_defineProperty(this, "backticks", {});
_defineProperty(this, "backticksScanned", false);
_defineProperty(this, "skipHtmlSpecial", false);
_defineProperty(this, "linkLevel", 0);
_defineProperty(this, "delimiters", []);
_defineProperty(this, "_prev_delimiters", []);
_defineProperty(this, "Token", Token);
this.src = e;
this.env = n;
this.md = t;
this.tokens = r;
this.tokens_meta = Array(r.length);
this.posMax = this.src.length;
}
pushPending() {
const e = new Token("text", "", 0);
e.content = this.pending;
e.level = this.pendingLevel;
this.tokens.push(e);
this.pending = "";
return e;
}
push(e, t, n) {
if (this.pending) this.pushPending();
const r = new Token(e, t, n);
let i = void 0;
if (n < 0) {
this.level--;
this.delimiters = this._prev_delimiters.pop();
}
r.level = this.level;
if (n > 0) {
this.level++;
this._prev_delimiters.push(this.delimiters);
this.delimiters = [];
i = { delimiters: this.delimiters };
}
this.pendingLevel = this.level;
this.tokens.push(r);
this.tokens_meta.push(i);
return r;
}
scanDelims(e, t) {
const n = this.posMax;
const r = this.src.charCodeAt(e);
let i;
if (e === 0) i = 32;
else if (e === 1) {
i = this.src.charCodeAt(0);
if ((i & 63488) === 55296) i = 65533;
} else {
i = this.src.charCodeAt(e - 1);
if ((i & 64512) === 56320) {
const t = this.src.charCodeAt(e - 2);
i = (t & 64512) === 55296 ? 65536 + (t - 55296 << 10) + (i - 56320) : 65533;
} else if ((i & 64512) === 55296) i = 65533;
}
let a = e;
while (a < n && this.src.charCodeAt(a) === r) a++;
const o = a - e;
let s = a < n ? this.src.charCodeAt(a) : 32;
if ((s & 64512) === 55296) {
const e = this.src.charCodeAt(a + 1);
s = (e & 64512) === 56320 ? 65536 + (s - 55296 << 10) + (e - 56320) : 65533;
} else if ((s & 64512) === 56320) s = 65533;
const c = isMdAsciiPunct(i) || isPunctCharCode(i);
const l = isMdAsciiPunct(s) || isPunctCharCode(s);
const u = isWhiteSpace(i);
const d = isWhiteSpace(s);
const f = !d && (!l || u || c);
const p = !u && (!c || d || l);
return {
can_open: f && (t || !p || c),
can_close: p && (t || !f || l),
length: o
};
}
};
function isTerminatorChar(e) {
switch (e) {
case 10:
case 33:
case 35:
case 36:
case 37:
case 38:
case 42:
case 43:
case 45:
case 58:
case 60:
case 61:
case 62:
case 64:
case 91:
case 92:
case 93:
case 94:
case 95:
case 96:
case 123:
case 125:
case 126: return true;
default: return false;
}
}
function text(e, t) {
let n = e.pos;
while (n < e.posMax && !isTerminatorChar(e.src.charCodeAt(n))) n++;
if (n === e.pos) return false;
if (!t) e.pending += e.src.slice(e.pos, n);
e.pos = n;
return true;
}
function isAsciiAlpha(e) {
return e >= 65 && e <= 90 || e >= 97 && e <= 122;
}
function isSchemeChar(e) {
return e >= 65 && e <= 90 || e >= 97 && e <= 122 || e >= 48 && e <= 57 || e === 43 || e === 45 || e === 46;
}
function linkify(e, t) {
if (!e.md.options.linkify) return false;
if (e.linkLevel > 0) return false;
const n = e.pos;
const r = e.posMax;
if (n + 3 > r) return false;
if (e.src.charCodeAt(n) !== 58) return false;
if (e.src.charCodeAt(n + 1) !== 47) return false;
if (e.src.charCodeAt(n + 2) !== 47) return false;
const i = n - Math.min(10, e.pending.length, n);
let a = n;
while (a > i && isSchemeChar(e.src.charCodeAt(a - 1))) a--;
if (a === n || !isAsciiAlpha(e.src.charCodeAt(a))) return false;
const o = n - a;
const s = e.md.linkify.matchAtStart(e.src.slice(a));
if (!s) return false;
let c = s.url;
if (c.length <= o) return false;
let l = c.length;
while (l > 0 && c.charCodeAt(l - 1) === 42) l--;
if (l !== c.length) c = c.slice(0, l);
const u = e.md.normalizeLink(c);
if (!e.md.validateLink(u)) return false;
if (!t) {
e.pending = e.pending.slice(0, -o);
const t = e.push("link_open", "a", 1);
t.attrs = [["href", u]];
t.markup = "linkify";
t.info = "auto";
const n = e.push("text", "", 0);
n.content = e.md.normalizeLinkText(c);
const r = e.push("link_close", "a", -1);
r.markup = "linkify";
r.info = "auto";
}
e.pos += c.length - o;
return true;
}
function newline(e, t) {
let n = e.pos;
if (e.src.charCodeAt(n) !== 10) return false;
const r = e.pending.length - 1;
const i = e.posMax;
if (!t) {
if (r >= 0 && e.pending.charCodeAt(r) === 32) {
if (r >= 1 && e.pending.charCodeAt(r - 1) === 32) {
let t = r - 1;
while (t >= 1 && e.pending.charCodeAt(t - 1) === 32) t--;
e.pending = e.pending.slice(0, t);
e.push("hardbreak", "br", 0);
} else {
e.pending = e.pending.slice(0, -1);
e.push("softbreak", "br", 0);
}
} else e.push("softbreak", "br", 0);
}
n++;
while (n < i && isSpace(e.src.charCodeAt(n))) n++;
e.pos = n;
return true;
}
var ESCAPED = [];
for (let e = 0; e < 256; e++) ESCAPED.push(0);
"\\!\"#$%&'()*+,./:;<=>?@[]^_`{|}~-".split("").forEach(function(e) {
ESCAPED[e.charCodeAt(0)] = 1;
});
function escape(e, t) {
let n = e.pos;
const r = e.posMax;
if (e.src.charCodeAt(n) !== 92) return false;
n++;
if (n >= r) return false;
let i = e.src.charCodeAt(n);
if (i === 10) {
if (!t) e.push("hardbreak", "br", 0);
n++;
while (n < r) {
i = e.src.charCodeAt(n);
if (!isSpace(i)) break;
n++;
}
e.pos = n;
return true;
}
if (i === 32) {
if (!t) {
const t = e.push("text_special", "", 0);
t.content = "\\";
t.markup = "\\";
t.info = "escape";
}
e.pos = n;
return true;
}
let a = e.src[n];
if (i >= 55296 && i <= 56319 && n + 1 < r) {
const t = e.src.charCodeAt(n + 1);
if (t >= 56320 && t <= 57343) {
a += e.src[n + 1];
n++;
}
}
const o = "\\" + a;
if (!t) {
const t = e.push("text_special", "", 0);
if (i < 256 && ESCAPED[i] !== 0) t.content = a;
else t.content = o;
t.markup = o;
t.info = "escape";
}
e.pos = n + 1;
return true;
}
function buildLastRuns(e) {
const t = {};
let n = 0;
while ((n = e.indexOf("`", n)) !== -1) {
const r = n;
while (e.charCodeAt(++n) === 96);
t[n - r] = r;
}
return t;
}
function backtick(e, t) {
var n;
const r = e.pos;
if (e.src.charCodeAt(r) !== 96) return false;
const i = e.posMax;
let a = r + 1;
while (a < i && e.src.charCodeAt(a) === 96) a++;
const o = e.src.slice(r, a);
const s = o.length;
if (!e.backticksScanned) {
e.backticks = buildLastRuns(e.src);
e.backticksScanned = true;
}
if (((n = e.backticks[s]) !== null && n !== void 0 ? n : -1) >= a) {
let n = a;
let r;
while ((r = e.src.indexOf("`", n)) !== -1 && r < i) {
n = r + 1;
while (e.src.charCodeAt(n) === 96) n++;
if (n > i) break;
if (n - r === s) {
if (!t) {
const t = e.push("code_inline", "code", 0);
t.markup = o;
let n = e.src.slice(a, r).replace(/\n/g, " ");
if (n.startsWith(" ") && n.endsWith(" ") && /[^ ]/.test(n)) n = n.slice(1, -1);
t.content = n;
}
e.pos = n;
return true;
}
}
}
if (!t) e.pending += o;
e.pos = a;
return true;
}
function strikethrough_tokenize(e, t) {
const n = e.pos;
const r = e.src.charCodeAt(n);
if (t) return false;
if (r !== 126) return false;
const i = e.scanDelims(e.pos, true);
let a = i.length;
const o = String.fromCharCode(r);
if (a < 2) return false;
let s;
if (a % 2) {
s = e.push("text", "", 0);
s.content = o;
a--;
}
for (let t = 0; t < a; t += 2) {
s = e.push("text", "", 0);
s.content = o + o;
e.delimiters.push({
marker: r,
length: 0,
token: e.tokens.length - 1,
end: -1,
open: i.can_open,
close: i.can_close
});
}
e.pos += i.length;
return true;
}
function postProcess$1(e, t) {
let n;
const r = [];
const i = t.length;
for (let a = 0; a < i; a++) {
const i = t[a];
if (i.marker !== 126) continue;
if (i.end === -1) continue;
const o = t[i.end];
n = e.tokens[i.token];
n.type = "s_open";
n.tag = "s";
n.nesting = 1;
n.markup = "~~";
n.content = "";
n = e.tokens[o.token];
n.type = "s_close";
n.tag = "s";
n.nesting = -1;
n.markup = "~~";
n.content = "";
if (e.tokens[o.token - 1].type === "text" && e.tokens[o.token - 1].content === "~") r.push(o.token - 1);
}
while (r.length) {
const t = r.pop();
let i = t + 1;
while (i < e.tokens.length && e.tokens[i].type === "s_close") i++;
i--;
if (t !== i) {
n = e.tokens[i];
e.tokens[i] = e.tokens[t];
e.tokens[t] = n;
}
}
}
function strikethrough_postProcess(e) {
const t = e.tokens_meta;
const n = e.tokens_meta.length;
postProcess$1(e, e.delimiters);
for (let i = 0; i < n; i++) {
var r;
const n = (r = t[i]) === null || r === void 0 ? void 0 : r.delimiters;
if (n) postProcess$1(e, n);
}
}
var strikethrough_default = {
tokenize: strikethrough_tokenize,
postProcess: strikethrough_postProcess
};
function emphasis_tokenize(e, t) {
const n = e.pos;
const r = e.src.charCodeAt(n);
if (t) return false;
if (r !== 95 && r !== 42) return false;
const i = e.scanDelims(e.pos, r === 42);
for (let t = 0; t < i.length; t++) {
const t = e.push("text", "", 0);
t.content = String.fromCharCode(r);
e.delimiters.push({
marker: r,
length: i.length,
token: e.tokens.length - 1,
end: -1,
open: i.can_open,
close: i.can_close
});
}
e.pos += i.length;
return true;
}
function postProcess(e, t) {
const n = t.length;
for (let r = n - 1; r >= 0; r--) {
const n = t[r];
if (n.marker !== 95 && n.marker !== 42) continue;
if (n.end === -1) continue;
const i = t[n.end];
const a = r > 0 && t[r - 1].end === n.end + 1 && t[r - 1].marker === n.marker && t[r - 1].token === n.token - 1 && t[n.end + 1].token === i.token + 1;
const o = String.fromCharCode(n.marker);
const s = e.tokens[n.token];
s.type = a ? "strong_open" : "em_open";
s.tag = a ? "strong" : "em";
s.nesting = 1;
s.markup = a ? o + o : o;
s.content = "";
const c = e.tokens[i.token];
c.type = a ? "strong_close" : "em_close";
c.tag = a ? "strong" : "em";
c.nesting = -1;
c.markup = a ? o + o : o;
c.content = "";
if (a) {
e.tokens[t[r - 1].token].content = "";
e.tokens[t[n.end + 1].token].content = "";
r--;
}
}
}
function emphasis_post_process(e) {
const t = e.tokens_meta;
const n = e.tokens_meta.length;
postProcess(e, e.delimiters);
for (let i = 0; i < n; i++) {
var r;
const n = (r = t[i]) === null || r === void 0 ? void 0 : r.delimiters;
if (n) postProcess(e, n);
}
}
var emphasis_default = {
tokenize: emphasis_tokenize,
postProcess: emphasis_post_process
};
function link(e, t) {
let n, r, i, a;
let o = "";
let s = "";
let c = e.pos;
let l = true;
if (e.src.charCodeAt(e.pos) !== 91) return false;
const u = e.pos;
const d = e.posMax;
const f = e.pos + 1;
const p = e.md.helpers.parseLinkLabel(e, e.pos, true);
if (p < 0) return false;
let m = p + 1;
if (m < d && e.src.charCodeAt(m) === 40) {
l = false;
m++;
for (; m < d; m++) {
n = e.src.charCodeAt(m);
if (!isSpace(n) && n !== 10) break;
}
if (m >= d) return false;
c = m;
i = e.md.helpers.parseLinkDestination(e.src, m, e.posMax);
if (i.ok) {
o = e.md.normalizeLink(i.str);
if (e.md.validateLink(o)) m = i.pos;
else o = "";
c = m;
for (; m < d; m++) {
n = e.src.charCodeAt(m);
if (!isSpace(n) && n !== 10) break;
}
i = e.md.helpers.parseLinkTitle(e.src, m, e.posMax);
if (m < d && c !== m && i.ok) {
s = i.str;
m = i.pos;
for (; m < d; m++) {
n = e.src.charCodeAt(m);
if (!isSpace(n) && n !== 10) break;
}
}
}
if (m >= d || e.src.charCodeAt(m) !== 41) l = true;
m++;
}
if (l) {
if (typeof e.env.references === "undefined") return false;
if (m < d && e.src.charCodeAt(m) === 91) {
c = m + 1;
m = e.md.helpers.parseLinkLabel(e, m);
if (m >= 0) r = e.src.slice(c, m++);
else m = p + 1;
} else m = p + 1;
if (!r) r = e.src.slice(f, p);
r = normalizeReference(r);
a = e.env.references[r];
if (!a) {
e.pos = u;
return false;
}
o = a.href;
s = a.title;
}
if (!t) {
e.pos = f;
e.posMax = p;
const t = e.push("link_open", "a", 1);
const n = [["href", o]];
t.attrs = n;
if (s) n.push(["title", s]);
if (r) {
const e = Object.create(null);
e.label = r;
t.meta = e;
}
e.linkLevel++;
e.md.inline.tokenize(e);
e.linkLevel--;
e.push("link_close", "a", -1);
}
e.pos = m;
e.posMax = d;
return true;
}
function image(e, t) {
let n, r, i, a, o, s, c, l;
let u = "";
const d = e.pos;
const f = e.posMax;
if (e.src.charCodeAt(e.pos) !== 33) return false;
if (e.src.charCodeAt(e.pos + 1) !== 91) return false;
const p = e.pos + 2;
const m = e.md.helpers.parseLinkLabel(e, e.pos + 1, false);
if (m < 0) return false;
a = m + 1;
if (a < f && e.src.charCodeAt(a) === 40) {
a++;
for (; a < f; a++) {
n = e.src.charCodeAt(a);
if (!isSpace(n) && n !== 10) break;
}
if (a >= f) return false;
l = a;
s = e.md.helpers.parseLinkDestination(e.src, a, e.posMax);
if (s.ok) {
u = e.md.normalizeLink(s.str);
if (e.md.validateLink(u)) a = s.pos;
else u = "";
}
l = a;
for (; a < f; a++) {
n = e.src.charCodeAt(a);
if (!isSpace(n) && n !== 10) break;
}
s = e.md.helpers.parseLinkTitle(e.src, a, e.posMax);
if (a < f && l !== a && s.ok) {
c = s.str;
a = s.pos;
for (; a < f; a++) {
n = e.src.charCodeAt(a);
if (!isSpace(n) && n !== 10) break;
}
} else c = "";
if (a >= f || e.src.charCodeAt(a) !== 41) {
e.pos = d;
return false;
}
a++;
} else {
if (typeof e.env.references === "undefined") return false;
if (a < f && e.src.charCodeAt(a) === 91) {
l = a + 1;
a = e.md.helpers.parseLinkLabel(e, a);
if (a >= 0) i = e.src.slice(l, a++);
else a = m + 1;
} else a = m + 1;
if (!i) i = e.src.slice(p, m);
i = normalizeReference(i);
o = e.env.references[i];
if (!o) {
e.pos = d;
return false;
}
u = o.href;
c = o.title;
}
if (!t) {
r = e.src.slice(p, m);
const t = [];
e.md.inline.parse(r, e.md, e.env, t);
const n = e.push("image", "img", 0);
const a = [["src", u], ["alt", ""]];
n.attrs = a;
n.children = t;
n.content = r;
if (c) a.push(["title", c]);
if (i) {
const e = Object.create(null);
e.label = i;
n.meta = e;
}
}
e.pos = a;
e.posMax = f;
return true;
}
var EMAIL_RE = /^([a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*)$/;
var AUTOLINK_RE = /^([a-zA-Z][a-zA-Z0-9+.-]{1,31}):([^<>\x00-\x20]*)$/;
function autolink(e, t) {
let n = e.pos;
if (e.src.charCodeAt(n) !== 60) return false;
const r = e.pos;
const i = e.posMax;
for (;;) {
if (++n >= i) return false;
const t = e.src.charCodeAt(n);
if (t === 60) return false;
if (t === 62) break;
}
const a = e.src.slice(r + 1, n);
if (AUTOLINK_RE.test(a)) {
const n = e.md.normalizeLink(a);
if (!e.md.validateLink(n)) return false;
if (!t) {
const t = e.push("link_open", "a", 1);
t.attrs = [["href", n]];
t.markup = "autolink";
t.info = "auto";
const r = e.push("text", "", 0);
r.content = e.md.normalizeLinkText(a);
const i = e.push("link_close", "a", -1);
i.markup = "autolink";
i.info = "auto";
}
e.pos += a.length + 2;
return true;
}
if (EMAIL_RE.test(a)) {
const n = e.md.normalizeLink(`mailto:${a}`);
if (!e.md.validateLink(n)) return false;
if (!t) {
const t = e.push("link_open", "a", 1);
t.attrs = [["href", n]];
t.markup = "autolink";
t.info = "auto";
const r = e.push("text", "", 0);
r.content = e.md.normalizeLinkText(a);
const i = e.push("link_close", "a", -1);
i.markup = "autolink";
i.info = "auto";
}
e.pos += a.length + 2;
return true;
}
return false;
}
function isLinkOpen(e) {
return /^<a[>\s]/i.test(e);
}
function isLinkClose(e) {
return /^<\/a\s*>/i.test(e);
}
function isLetter(e) {
const t = e | 32;
return t >= 97 && t <= 122;
}
function scanSpecial(e, t) {
const n = e.src;
let r;
let i;
if (n.startsWith("<!--", t)) {
if (n.startsWith(">", t + 4)) return t + 5;
if (n.startsWith("->", t + 4)) return t + 6;
r = t + 4;
i = "-->";
} else if (n.startsWith("<![CDATA[", t)) {
r = t + 9;
i = "]]>";
} else if (n.charCodeAt(t + 1) === 63) {
r = t + 2;
i = "?>";
} else if (isLetter(n.charCodeAt(t + 2))) {
r = t + 3;
i = ">";
} else return -1;
if (e.skipHtmlSpecial) return -1;
const a = n.indexOf(i, r);
if (a < 0) {
e.skipHtmlSpecial = true;
return -1;
}
return a + i.length;
}
function html_inline(e, t) {
if (!e.md.options.html) return false;
const n = e.posMax;
const r = e.pos;
if (e.src.charCodeAt(r) !== 60 || r + 2 >= n) return false;
let i;
const a = e.src.charCodeAt(r + 1);
if (a === 33 || a === 63) i = scanSpecial(e, r);
else if (a === 47 || isLetter(a)) {
const t = e.src.slice(r).match(HTML_OPEN_CLOSE_TAG_RE);
i = t ? r + t[0].length : -1;
} else return false;
if (i < 0) return false;
if (!t) {
const t = e.push("html_inline", "", 0);
t.content = e.src.slice(r, i);
if (isLinkOpen(t.content)) e.linkLevel++;
if (isLinkClose(t.content)) e.linkLevel--;
}
e.pos = i;
return true;
}
var DIGITAL_RE = /^&#((?:x[a-f0-9]{1,6}|[0-9]{1,7}));/i;
var NAMED_RE = /^&([a-z][a-z0-9]{1,31});/i;
function entity(e, t) {
const n = e.pos;
const r = e.posMax;
if (e.src.charCodeAt(n) !== 38) return false;
if (n + 1 >= r) return false;
if (e.src.charCodeAt(n + 1) === 35) {
const r = e.src.slice(n).match(DIGITAL_RE);
if (r) {
if (!t) {
const t = r[1][0].toLowerCase() === "x" ? parseInt(r[1].slice(1), 16) : parseInt(r[1], 10);
const n = e.push("text_special", "", 0);
n.content = isValidEntityCode(t) ? fromCodePoint(t) : fromCodePoint(65533);
n.markup = r[0];
n.info = "entity";
}
e.pos += r[0].length;
return true;
}
} else {
const r = e.src.slice(n).match(NAMED_RE);
if (r) {
const n = decodeHTMLStrict(r[0]);
if (n !== r[0]) {
if (!t) {
const t = e.push("text_special", "", 0);
t.content = n;
t.markup = r[0];
t.info = "entity";
}
e.pos += r[0].length;
return true;
}
}
}
return false;
}
function processDelimiters(e) {
const t = {};
const n = e.length;
if (!n) return;
let r = 0;
let i = -2;
const a = [];
for (let o = 0; o < n; o++) {
const n = e[o];
a.push(0);
if (e[r].marker !== n.marker || i !== n.token - 1) r = o;
i = n.token;
n.length = n.length || 0;
if (!n.close) continue;
if (!t.hasOwnProperty(n.marker)) t[n.marker] = [
-1,
-1,
-1,
-1,
-1,
-1
];
const s = t[n.marker][(n.open ? 3 : 0) + n.length % 3];
let c = r - a[r] - 1;
let l = c;
for (; c > s; c -= a[c] + 1) {
const t = e[c];
if (t.marker !== n.marker) continue;
if (t.open && t.end < 0) {
let r = false;
if (t.close || n.open) {
if ((t.length + n.length) % 3 === 0) {
if (t.length % 3 !== 0 || n.length % 3 !== 0) r = true;
}
}
if (!r) {
const r = c > 0 && !e[c - 1].open ? a[c - 1] + 1 : 0;
a[o] = o - c + r;
a[c] = r;
n.open = false;
t.end = o;
t.close = false;
l = -1;
i = -2;
break;
}
}
}
if (l !== -1) t[n.marker][(n.open ? 3 : 0) + (n.length || 0) % 3] = l;
}
}
function link_pairs(e) {
const t = e.tokens_meta;
const n = e.tokens_meta.length;
processDelimiters(e.delimiters);
for (let e = 0; e < n; e++) {
var r;
const n = (r = t[e]) === null || r === void 0 ? void 0 : r.delimiters;
if (n) processDelimiters(n);
}
}
function fragments_join(e) {
let t, n;
let r = 0;
const i = e.tokens;
const a = e.tokens.length;
for (t = n = 0; t < a; t++) {
if (i[t].nesting < 0) r--;
i[t].level = r;
if (i[t].nesting > 0) r++;
if (i[t].type === "text" && t + 1 < a && i[t + 1].type === "text") i[t + 1].content = i[t].content + i[t + 1].content;
else {
if (t !== n) i[n] = i[t];
n++;
}
}
if (t !== n) i.length = n;
}
var _rules = [
["text", text],
["linkify", linkify],
["newline", newline],
["escape", escape],
["backticks", backtick],
["strikethrough", strikethrough_default.tokenize],
["emphasis", emphasis_default.tokenize],
["link", link],
["image", image],
["autolink", autolink],
["html_inline", html_inline],
["entity", entity]
];
var _rules2 = [
["balance_pairs", link_pairs],
["strikethrough", strikethrough_default.postProcess],
["emphasis", emphasis_default.postProcess],
["fragments_join", fragments_join]
];
/**
* Tokenizes paragraph content.
*/
var ParserInline = class {
constructor() {
_defineProperty(
this,
/**
* {@link Ruler} instance. Keep configuration of inline rules.
*/
"ruler",
new Ruler()
);
_defineProperty(
this,
/**
* {@link Ruler} instance. Second ruler used for post-processing
* (e.g. in emphasis-like rules).
*/
"ruler2",
new Ruler()
);
_defineProperty(this, "State", StateInline);
for (let e = 0; e < _rules.length; e++) this.ruler.push(_rules[e][0], _rules[e][1]);
for (let e = 0; e < _rules2.length; e++) this.ruler2.push(_rules2[e][0], _rules2[e][1]);
}
skipToken(e) {
const t = e.pos;
const n = this.ruler.getRules("");
const r = n.length;
const i = e.md.options.maxNesting;
const a = e.cache;
if (typeof a[t] !== "undefined") {
e.pos = a[t];
return;
}
let o = false;
if (e.level < i) for (let i = 0; i < r; i++) {
e.level++;
o = n[i](e, true);
e.level--;
if (o) {
if (t >= e.pos) throw new Error("inline rule didn't increment state.pos");
break;
}
}
else e.pos = e.posMax;
if (!o) e.pos++;
a[t] = e.pos;
}
tokenize(e) {
const t = this.ruler.getRules("");
const n = t.length;
const r = e.posMax;
const i = e.md.options.maxNesting;
while (e.pos < r) {
const a = e.pos;
let o = false;
if (e.level < i) for (let r = 0; r < n; r++) {
o = t[r](e, false);
if (o) {
if (a >= e.pos) throw new Error("inline rule didn't increment state.pos");
break;
}
}
if (o) {
if (e.pos >= r) break;
continue;
}
e.pending += e.src[e.pos++];
}
if (e.pending) e.pushPending();
}
/**
* Process input string and push inline tokens into `outTokens`
*/
parse(e, t, n, r) {
const i = new this.State(e, t, n, r);
this.tokenize(i);
const a = this.ruler2.getRules("");
const o = a.length;
for (let e = 0; e < o; e++) a[e](i);
}
};
var config = {
default: {
options: {
html: false,
xhtmlOut: false,
breaks: false,
langPrefix: "language-",
linkify: false,
typographer: false,
quotes: "“”‘’",
highlight: null,
maxNesting: 100
},
components: {
core: {},
block: {},
inline: {}
}
},
zero: {
options: {
html: false,
xhtmlOut: false,
breaks: false,
langPrefix: "language-",
linkify: false,
typographer: false,
quotes: "“”‘’",
highlight: null,
maxNesting: 20
},
components: {
core: { rules: [
"normalize",
"block",
"strip_references",
"inline",
"text_join"
] },
block: { rules: ["paragraph"] },
inline: {
rules: ["text"],
rules2: ["balance_pairs", "fragments_join"]
}
}
},
commonmark: {
options: {
html: true,
xhtmlOut: true,
breaks: false,
langPrefix: "language-",
linkify: false,
typographer: false,
quotes: "“”‘’",
highlight: null,
maxNesting: 20
},
components: {
core: { rules: [
"normalize",
"block",
"strip_references",
"inline",
"text_join"
] },
block: { rules: [
"blockquote",
"code",
"fence",
"heading",
"hr",
"html_block",
"lheading",
"list",
"reference",
"paragraph"
] },
inline: {
rules: [
"autolink",
"backticks",
"emphasis",
"entity",
"escape",
"html_inline",
"image",
"link",
"newline",
"text"
],
rules2: [
"balance_pairs",
"emphasis",
"fragments_join"
]
}
}
}
};
var BAD_PROTO_RE = /^(vbscript|javascript|file|data):/;
var GOOD_DATA_RE = /^data:image\/(gif|png|jpeg|webp);/;
var RECODE_HOSTNAME_FOR = [
"http:",
"https:",
"mailto:"
];
/**
* Parses Markdown into tokens and renders them to HTML.
*
* @category Main
*/
var MarkdownIt = class {
/**
* Link validation function. CommonMark allows too much in links. By default
* we disable `javascript:`, `vbscript:`, `file:` schemas, and almost all `data:...` schemas
* except some embedded image types.
*
* You can change this behaviour:
*
* @example
* ```javascript
* import MarkdownIt from 'markdown-it'
* const md = new MarkdownIt()
*
* // enable everything
* md.validateLink = function () { return true; }
* ```
*/
validateLink(e) {
const t = e.trim().toLowerCase();
return BAD_PROTO_RE.test(t) ? GOOD_DATA_RE.test(t) : true;
}
/**
* Function used to encode link url to a machine-readable format,
* which includes url-encoding, punycode, etc.
*/
normalizeLink(e) {
const t = urlParse(e, true);
if (t.hostname) {
if (!t.protocol || RECODE_HOSTNAME_FOR.indexOf(t.protocol) >= 0) try {
t.hostname = import_punycode.default.toASCII(t.hostname);
} catch (e) {}
}
if (t.auth) t.auth = encode(t.auth);
if (t.hostname) t.hostname = encode(t.hostname);
if (t.pathname) t.pathname = encode(t.pathname);
if (t.search) t.search = encode(t.search);
if (t.hash) t.hash = encode(t.hash);
return format(t);
}
/**
* Function used to decode link url to a human-readable format`
*/
normalizeLinkText(e) {
const t = urlParse(e, true);
if (t.hostname) {
if (!t.protocol || RECODE_HOSTNAME_FOR.indexOf(t.protocol) >= 0) try {
t.hostname = import_punycode.default.toUnicode(t.hostname);
} catch (e) {}
}
return decode(format(t), decode.defaultChars + "%");
}
constructor(...e) {
_defineProperty(
this,
/**
* Instance of {@link ParserInline}. You may need it to add new rules when
* writing plugins. For simple rules control use {@link MarkdownIt.disable}
* and {@link MarkdownIt.enable}.
*/
"inline",
new ParserInline()
);
_defineProperty(
this,
/**
* Instance of {@link ParserBlock}. You may need it to add new rules when
* writing plugins. For simple rules control use {@link MarkdownIt.disable}
* and {@link MarkdownIt.enable}.
*/
"block",
new ParserBlock()
);
_defineProperty(
this,
/**
* Instance of {@link ParserCore} chain executor. You may need it to add new
* rules when writing plugins. For simple rules control use
* {@link MarkdownIt.disable} and {@link MarkdownIt.enable}.
*/
"core",
new ParserCore()
);
_defineProperty(
this,
/**
* Instance of {@link Renderer}. Use it to modify output look. Or to add rendering
* rules for new token types, generated by plugins.
*
* See {@link Renderer} docs and
* [source code](https://github.com/markdown-it/markdown-it/blob/master/src/renderer.ts).
*
* @example
* ```javascript
* import MarkdownIt from 'markdown-it'
* const md = new MarkdownIt()
*
* function myToken(tokens, idx, options, env, self) {
* //...
* return result;
* };
*
* md.renderer.rules['my_token'] = myToken
* ```
*/
"renderer",
new Renderer()
);
_defineProperty(
this,
/**
* [linkify-it](https://github.com/markdown-it/linkify-it) instance.
* Used by [linkify](https://github.com/markdown-it/markdown-it/blob/master/src/rules_core/linkify.ts)
* rule.
*/
"linkify",
new LinkifyIt()
);
_defineProperty(
this,
/**
* Assorted utility functions, useful to write plugins. See details
* [here](https://github.com/markdown-it/markdown-it/blob/master/src/common/utils.ts).
*/
"utils",
utils_exports
);
_defineProperty(
this,
/**
* Link components parser functions, useful to write plugins. See details
* [here](https://github.com/markdown-it/markdown-it/blob/master/src/helpers).
*/
"helpers",
Object.assign({}, helpers_exports)
);
const [t, n] = e;
if (typeof t === "string") {
this.configure(t);
if (n) this.set(n);
} else {
this.configure("default");
this.set(t || {});
}
}
/**
* Set parser options (in the same format as in constructor). Probably, you
* will never need it, but you can change options after constructor call.
*
* __Note:__ To achieve the best possible performance, don't modify a
* `markdown-it` instance options on the fly. If you need multiple configurations
* it's best to create multiple instances and initialize each with separate
* config.
*
* @example
* ```javascript
* import MarkdownIt from 'markdown-it'
*
* const md = new MarkdownIt()
* .set({ html: true, breaks: true })
* .set({ typographer: true })
* ```
*/
set(e) {
Object.assign(this.options, e);
return this;
}
/**
* Batch load of all options and compenent settings. This is internal method,
* and you probably will not need it. But if you will - see available presets
* and data structure [here](https://github.com/markdown-it/markdown-it/tree/master/src/presets)
*
* We strongly recommend to use presets instead of direct config loads. That
* will give better compatibility with next versions.
*/
configure(e) {
let t;
if (typeof e === "string") {
const n = e;
t = config[n];
if (!t) throw new Error(`Wrong 'markdown-it' preset "${n}", check name`);
} else t = e;
if (!t) throw new Error("Wrong `markdown-it` preset, can't be empty");
if (t.options) this.options = { ...t.options };
const n = t.components;
if (n) {
var r;
[
"core",
"block",
"inline"
].forEach((e) => {
var t;
const r = (t = n[e]) === null || t === void 0 ? void 0 : t.rules;
if (r) this[e].ruler.enableOnly(r);
});
const e = (r = n.inline) === null || r === void 0 ? void 0 : r.rules2;
if (e) this.inline.ruler2.enableOnly(e);
}
return this;
}
/**
* Enable list or rules. It will automatically find appropriate components,
* containing rules with given names. If rule not found, and `ignoreInvalid`
* not set - throws exception.
*
* @example
* ```javascript
* import MarkdownIt from 'markdown-it'
*
* const md = new MarkdownIt()
* .enable(['sub', 'sup'])
* .disable('smartquotes')
* ```
*/
enable(e, t = false) {
let n = [];
if (!Array.isArray(e)) e = [e];
[
"core",
"block",
"inline"
].forEach((t) => {
n = n.concat(this[t].ruler.enable(e, true));
});
n = n.concat(this.inline.ruler2.enable(e, true));
const r = e.filter((e) => n.indexOf(e) < 0);
if (r.length && !t) throw new Error(`MarkdownIt. Failed to enable unknown rule(s): ${r}`);
return this;
}
/**
* The same as {@link MarkdownIt.enable}, but turn specified rules off.
*/
disable(e, t = false) {
let n = [];
if (!Array.isArray(e)) e = [e];
[
"core",
"block",
"inline"
].forEach((t) => {
n = n.concat(this[t].ruler.disable(e, true));
});
n = n.concat(this.inline.ruler2.disable(e, true));
const r = e.filter((e) => n.indexOf(e) < 0);
if (r.length && !t) throw new Error(`MarkdownIt. Failed to disable unknown rule(s): ${r}`);
return this;
}
/**
* Load specified plugin with given params into current parser instance.
* It's just a sugar to call `plugin(md, params)` with curring.
*
* @example
* ```javascript
* import MarkdownIt from 'markdown-it'
* import iterator from 'markdown-it-for-inline'
*
* const md = new MarkdownIt()
* .use(iterator, 'foo_replace', 'text', function (tokens, idx) {
* tokens[idx].content = tokens[idx].content.replace(/foo/g, 'bar')
* })
* ```
*/
use(e, ...t) {
e.apply(e, [this, ...t]);
return this;
}
/**
* Parse input string and return list of block tokens (special token type
* "inline" will contain list of inline tokens). You should not call this
* method directly, until you write custom renderer (for example, to produce
* AST).
*
* `env` is used to pass data between "distributed" rules and return additional
* metadata like reference info, needed for the renderer. It also can be used to
* inject data in specific cases. Usually, you will be ok to pass `{}`,
* and then pass updated object to renderer.
*/
parse(e, t) {
if (typeof e !== "string") throw new Error("Input data should be a String");
const n = new this.core.State(e, this, t);
this.core.process(n);
return n.tokens;
}
/**
* Render markdown string into html. It does all magic for you :).
*
* `env` can be used to inject additional metadata (`{}` by default).
* But you will not need it with high probability. See also comment
* in {@link MarkdownIt.parse}.
*/
render(e, t = {}) {
return this.renderer.render(this.parse(e, t), this.options, t);
}
/**
* The same as {@link MarkdownIt.parse} but skip all block rules. It returns
* the block tokens list with the single `inline` element, containing parsed
* inline tokens in `children` property. Also updates `env` object.
*/
parseInline(e, t) {
const n = new this.core.State(e, this, t);
n.inlineMode = true;
this.core.process(n);
return n.tokens;
}
/**
* Similar to {@link MarkdownIt.render} but for single paragraph content.
* Result will NOT be wrapped into `<p>` tags.
*/
renderInline(e, t = {}) {
return this.renderer.render(this.parseInline(e, t), this.options, t);
}
};
_defineProperty(MarkdownIt, "Token", Token);
_defineProperty(MarkdownIt, "Ruler", Ruler);
_defineProperty(MarkdownIt, "Renderer", Renderer);
_defineProperty(MarkdownIt, "ParserCore", ParserCore);
_defineProperty(MarkdownIt, "StateCore", StateCore);
_defineProperty(MarkdownIt, "ParserBlock", ParserBlock);
_defineProperty(MarkdownIt, "StateBlock", StateBlock);
_defineProperty(MarkdownIt, "ParserInline", ParserInline);
_defineProperty(MarkdownIt, "StateInline", StateInline);
/**
* Default package export.
*
* For backward compatibility, the {@link MarkdownIt} class is wrapped so
* legacy code can call it without `new`. New code should instantiate it as a
* regular class with `new`. The compatibility wrapper may be removed in a
* future release.
*
* @category Main
*/
var MarkdownItCallable = callable(MarkdownIt);
//#endregion
export { MarkdownItCallable as t };