${parts[i]}`;
}
return out;
}
/** @param {string} s escaped @param {Options} o */
function marks(s, o) {
const held = [];
const hold = (html) => `\u0000${held.push(html) - 1}\u0000`;
s = s
.replace(WIKI, (_, embed, target, alias) => {
const [title, heading] = unescapeHtml(target).split("#");
const name = title.trim();
const shown = alias ?? target;
const href = o.resolve(name);
const anchor = heading ? `#${slug(heading)}` : "";
return hold(
href === null
? `${shown}`
: `${shown}`,
);
})
.replace(/\[([^\]\n]+)\]\(([^)\s]+)\)/g, (whole, label, url) =>
SAFE_URL.test(unescapeHtml(url))
? hold(`${label}`)
: whole,
)
.replace(/(^|[\s(])(https?:\/\/(?:(?!&(?:quot|#39|lt|gt);)[^\s<])*[^\s<.,;:!?)'"&])/g, (_, lead, url) =>
lead + hold(`${url}`),
)
.replace(TAG, (_, lead, tag) =>
lead + hold(`#${tag}`),
);
s = s
.replace(/\*\*(?=\S)([^*]*?\S)\*\*/g, "$1")
.replace(/__(?=\S)([^_]*?\S)__/g, "$1")
.replace(/(^|[^*\w])\*(?=\S)([^*]*?\S)\*(?!\w)/g, "$1$2")
.replace(/(^|[^_\w])_(?=\S)([^_]*?\S)_(?!\w)/g, "$1$2")
.replace(/~~(?=\S)([^~]*?\S)~~/g, "${para.map((l) => inline(escapeHtml(l), o)).join("
")}
${escapeHtml(code.join("\n"))}\n`;
} else if ((m = /^(#{1,6})[ \t]+(.*?)[ \t]*#*[ \t]*$/.exec(line))) {
flush();
const n = m[1].length;
out += `${inline(escapeHtml(heading), o)}
${blocks(quoted.slice(1), o).trimEnd()}${blocks(quoted, o).trimEnd()}\n`; } else if (/^\s*([-*+]|\d+[.)])\s/.test(line)) { flush(); const items = []; while (i < lines.length && (/^\s*([-*+]|\d+[.)])\s/.test(lines[i]) || (/^\s{2,}\S/.test(lines[i]) && items.length > 0))) items.push(lines[i++]); out += list(items, o); } else if (/^\s*\|.*\|\s*$/.test(line) && /^\s*\|?[\s:|-]*-[\s:|-]*\|?\s*$/.test(lines[i + 1] ?? "")) { flush(); const cells = (l) => l.trim().replace(/^\||\|$/g, "").split("|").map((c) => c.trim()); const head = cells(line); const align = cells(lines[i + 1]).map((c) => (c.startsWith(":") && c.endsWith(":") ? "center" : c.endsWith(":") ? "right" : "")); const style = (k) => (align[k] ? ` style="text-align:${align[k]}"` : ""); i += 2; let body = ""; while (i < lines.length && /^\s*\|.*\|\s*$/.test(lines[i])) { body += `
| ${inline(escapeHtml(c), o)} | `).join("")}
|---|