import { __commonJS } from "./chunk-TKSB4YUA.js"; // node_modules/markdown-it-attrs/utils.js var require_utils = __commonJS({ "node_modules/markdown-it-attrs/utils.js"(exports) { exports.getAttrs = function(str, start, options) { const allowedKeyChars = /[^\t\n\f />"'=]/; const pairSeparator = " "; const keySeparator = "="; const classChar = "."; const idChar = "#"; const attrs = []; let key = ""; let value = ""; let parsingKey = true; let valueInsideQuotes = false; for (let i = start + options.leftDelimiter.length; i < str.length; i++) { if (str.slice(i, i + options.rightDelimiter.length) === options.rightDelimiter) { if (key !== "") { attrs.push([key, value]); } break; } const char_ = str.charAt(i); if (char_ === keySeparator && parsingKey) { parsingKey = false; continue; } if (char_ === classChar && key === "") { if (str.charAt(i + 1) === classChar) { key = "css-module"; i += 1; } else { key = "class"; } parsingKey = false; continue; } if (char_ === idChar && key === "") { key = "id"; parsingKey = false; continue; } if (char_ === '"' && value === "" && !valueInsideQuotes) { valueInsideQuotes = true; continue; } if (char_ === '"' && valueInsideQuotes) { valueInsideQuotes = false; continue; } if (char_ === pairSeparator && !valueInsideQuotes) { if (key === "") { continue; } attrs.push([key, value]); key = ""; value = ""; parsingKey = true; continue; } if (parsingKey && char_.search(allowedKeyChars) === -1) { continue; } if (parsingKey) { key += char_; continue; } value += char_; } if (options.allowedAttributes && options.allowedAttributes.length) { const allowedAttributes = options.allowedAttributes; return attrs.filter(function(attrPair) { const attr = attrPair[0]; function isAllowedAttribute(allowedAttribute) { return attr === allowedAttribute || allowedAttribute instanceof RegExp && allowedAttribute.test(attr); } return allowedAttributes.some(isAllowedAttribute); }); } return attrs; }; exports.addAttrs = function(attrs, token) { for (let j = 0, l = attrs.length; j < l; ++j) { const key = attrs[j][0]; if (key === "class") { token.attrJoin("class", attrs[j][1]); } else if (key === "css-module") { token.attrJoin("css-module", attrs[j][1]); } else { token.attrPush(attrs[j]); } } return token; }; exports.hasDelimiters = function(where, options) { if (!where) { throw new Error('Parameter `where` not passed. Should be "start", "end" or "only".'); } return function(str) { const minCurlyLength = options.leftDelimiter.length + 1 + options.rightDelimiter.length; if (!str || typeof str !== "string" || str.length < minCurlyLength) { return false; } function validCurlyLength(curly) { const isClass = curly.charAt(options.leftDelimiter.length) === "."; const isId = curly.charAt(options.leftDelimiter.length) === "#"; return isClass || isId ? curly.length >= minCurlyLength + 1 : curly.length >= minCurlyLength; } let start, end, slice, nextChar; const rightDelimiterMinimumShift = minCurlyLength - options.rightDelimiter.length; switch (where) { case "start": slice = str.slice(0, options.leftDelimiter.length); start = slice === options.leftDelimiter ? 0 : -1; end = start === -1 ? -1 : str.indexOf(options.rightDelimiter, rightDelimiterMinimumShift); nextChar = str.charAt(end + options.rightDelimiter.length); if (nextChar && options.rightDelimiter.indexOf(nextChar) !== -1) { end = -1; } break; case "end": start = str.lastIndexOf(options.leftDelimiter); end = start === -1 ? -1 : str.indexOf(options.rightDelimiter, start + rightDelimiterMinimumShift); end = end === str.length - options.rightDelimiter.length ? end : -1; break; case "only": slice = str.slice(0, options.leftDelimiter.length); start = slice === options.leftDelimiter ? 0 : -1; slice = str.slice(str.length - options.rightDelimiter.length); end = slice === options.rightDelimiter ? str.length - options.rightDelimiter.length : -1; break; default: throw new Error(`Unexpected case ${where}, expected 'start', 'end' or 'only'`); } return start !== -1 && end !== -1 && validCurlyLength(str.substring(start, end + options.rightDelimiter.length)); }; }; exports.removeDelimiter = function(str, options) { const start = escapeRegExp(options.leftDelimiter); const end = escapeRegExp(options.rightDelimiter); const curly = new RegExp( "[ \\n]?" + start + "[^" + start + end + "]+" + end + "$" ); const pos = str.search(curly); return pos !== -1 ? str.slice(0, pos) : str; }; function escapeRegExp(s) { return s.replace(/[-/\\^$*+?.()|[\]{}]/g, "\\$&"); } exports.escapeRegExp = escapeRegExp; exports.getMatchingOpeningToken = function(tokens, i) { if (tokens[i].type === "softbreak") { return false; } if (tokens[i].nesting === 0) { return tokens[i]; } const level = tokens[i].level; const type = tokens[i].type.replace("_close", "_open"); for (; i >= 0; --i) { if (tokens[i].type === type && tokens[i].level === level) { return tokens[i]; } } return false; }; var HTML_ESCAPE_TEST_RE = /[&<>"]/; var HTML_ESCAPE_REPLACE_RE = /[&<>"]/g; var HTML_REPLACEMENTS = { "&": "&", "<": "<", ">": ">", '"': """ }; function replaceUnsafeChar(ch) { return HTML_REPLACEMENTS[ch]; } exports.escapeHtml = function(str) { if (HTML_ESCAPE_TEST_RE.test(str)) { return str.replace(HTML_ESCAPE_REPLACE_RE, replaceUnsafeChar); } return str; }; } }); // node_modules/markdown-it-attrs/patterns.js var require_patterns = __commonJS({ "node_modules/markdown-it-attrs/patterns.js"(exports, module) { "use strict"; var utils = require_utils(); module.exports = (options) => { const __hr = new RegExp("^ {0,3}[-*_]{3,} ?" + utils.escapeRegExp(options.leftDelimiter) + "[^" + utils.escapeRegExp(options.rightDelimiter) + "]"); return [ { /** * ```python {.cls} * for i in range(10): * print(i) * ``` */ name: "fenced code blocks", tests: [ { shift: 0, block: true, info: utils.hasDelimiters("end", options) } ], transform: (tokens, i) => { const token = tokens[i]; const start = token.info.lastIndexOf(options.leftDelimiter); const attrs = utils.getAttrs(token.info, start, options); utils.addAttrs(attrs, token); token.info = utils.removeDelimiter(token.info, options); } }, { /** * bla `click()`{.c} ![](img.png){.d} * * differs from 'inline attributes' as it does * not have a closing tag (nesting: -1) */ name: "inline nesting 0", tests: [ { shift: 0, type: "inline", children: [ { shift: -1, type: (str) => str === "image" || str === "code_inline" }, { shift: 0, type: "text", content: utils.hasDelimiters("start", options) } ] } ], /** * @param {!number} j */ transform: (tokens, i, j) => { const token = tokens[i].children[j]; const endChar = token.content.indexOf(options.rightDelimiter); const attrToken = tokens[i].children[j - 1]; const attrs = utils.getAttrs(token.content, 0, options); utils.addAttrs(attrs, attrToken); if (token.content.length === endChar + options.rightDelimiter.length) { tokens[i].children.splice(j, 1); } else { token.content = token.content.slice(endChar + options.rightDelimiter.length); } } }, { /** * | h1 | * | -- | * | c1 | * * {.c} */ name: "tables", tests: [ { // let this token be i, such that for-loop continues at // next token after tokens.splice shift: 0, type: "table_close" }, { shift: 1, type: "paragraph_open" }, { shift: 2, type: "inline", content: utils.hasDelimiters("only", options) } ], transform: (tokens, i) => { const token = tokens[i + 2]; const tableOpen = utils.getMatchingOpeningToken(tokens, i); const attrs = utils.getAttrs(token.content, 0, options); utils.addAttrs(attrs, tableOpen); tokens.splice(i + 1, 3); } }, { /** * | A | B | * | -- | -- | * | 1 | 2 | * * | C | D | * | -- | -- | * * only `| A | B |` sets the colsnum metadata */ name: "tables thead metadata", tests: [ { shift: 0, type: "tr_close" }, { shift: 1, type: "thead_close" }, { shift: 2, type: "tbody_open" } ], transform: (tokens, i) => { const tr = utils.getMatchingOpeningToken(tokens, i); const th = tokens[i - 1]; let colsnum = 0; let n = i; while (--n) { if (tokens[n] === tr) { tokens[n - 1].meta = Object.assign({}, tokens[n + 2].meta, { colsnum }); break; } colsnum += (tokens[n].level === th.level && tokens[n].type === th.type) >> 0; } tokens[i + 2].meta = Object.assign({}, tokens[i + 2].meta, { colsnum }); } }, { /** * | A | B | C | D | * | -- | -- | -- | -- | * | 1 | 11 | 111 | 1111 {rowspan=3} | * | 2 {colspan=2 rowspan=2} | 22 | 222 | 2222 | * | 3 | 33 | 333 | 3333 | */ name: "tables tbody calculate", tests: [ { shift: 0, type: "tbody_close", hidden: false } ], /** * @param {number} i index of the tbody ending */ transform: (tokens, i) => { let idx = i - 2; while (idx > 0 && "tbody_open" !== tokens[--idx].type) ; const calc = tokens[idx].meta.colsnum >> 0; if (calc < 2) { return; } const level = tokens[i].level + 2; for (let n = idx; n < i; n++) { if (tokens[n].level > level) { continue; } const token = tokens[n]; const rows = token.hidden ? 0 : token.attrGet("rowspan") >> 0; const cols = token.hidden ? 0 : token.attrGet("colspan") >> 0; if (rows > 1) { let colsnum = calc - (cols > 0 ? cols : 1); for (let k = n, num = rows; k < i, num > 1; k++) { if ("tr_open" == tokens[k].type) { tokens[k].meta = Object.assign({}, tokens[k].meta); if (tokens[k].meta && tokens[k].meta.colsnum) { colsnum -= 1; } tokens[k].meta.colsnum = colsnum; num--; } } } if ("tr_open" == token.type && token.meta && token.meta.colsnum) { const max = token.meta.colsnum; for (let k = n, num = 0; k < i; k++) { if ("td_open" == tokens[k].type) { num += 1; } else if ("tr_close" == tokens[k].type) { break; } num > max && (tokens[k].hidden || hidden(tokens[k])); } } if (cols > 1) { const one = []; let end = n + 3; let num = calc; for (let k = n; k > idx; k--) { if ("tr_open" == tokens[k].type) { num = tokens[k].meta && tokens[k].meta.colsnum || num; break; } else if ("td_open" === tokens[k].type) { one.unshift(k); } } for (let k = n + 2; k < i; k++) { if ("tr_close" == tokens[k].type) { end = k; break; } else if ("td_open" == tokens[k].type) { one.push(k); } } const off = one.indexOf(n); let real = num - off; real = real > cols ? cols : real; cols > real && token.attrSet("colspan", real + ""); for (let k = one.slice(num + 1 - calc - real)[0]; k < end; k++) { tokens[k].hidden || hidden(tokens[k]); } } } } }, { /** * *emphasis*{.with attrs=1} */ name: "inline attributes", tests: [ { shift: 0, type: "inline", children: [ { shift: -1, nesting: -1 // closing inline tag, {.a} }, { shift: 0, type: "text", content: utils.hasDelimiters("start", options) } ] } ], /** * @param {!number} j */ transform: (tokens, i, j) => { const token = tokens[i].children[j]; const content = token.content; const attrs = utils.getAttrs(content, 0, options); const openingToken = utils.getMatchingOpeningToken(tokens[i].children, j - 1); utils.addAttrs(attrs, openingToken); token.content = content.slice(content.indexOf(options.rightDelimiter) + options.rightDelimiter.length); } }, { /** * - item * {.a} */ name: "list softbreak", tests: [ { shift: -2, type: "list_item_open" }, { shift: 0, type: "inline", children: [ { position: -2, type: "softbreak" }, { position: -1, type: "text", content: utils.hasDelimiters("only", options) } ] } ], /** * @param {!number} j */ transform: (tokens, i, j) => { const token = tokens[i].children[j]; const content = token.content; const attrs = utils.getAttrs(content, 0, options); let ii = i - 2; while (tokens[ii - 1] && tokens[ii - 1].type !== "ordered_list_open" && tokens[ii - 1].type !== "bullet_list_open") { ii--; } utils.addAttrs(attrs, tokens[ii - 1]); tokens[i].children = tokens[i].children.slice(0, -2); } }, { /** * - nested list * - with double \n * {.a} <-- apply to nested ul * * {.b} <-- apply to root