extensions = {
const inlineRule = /^(\$+)([^\$]|[^\$][\s\S]*?[^\$])\1(?!\$)/;
const blockRule = /^(\${2})\n(?:|([\s\S]*?)\n)(?: {0,3}\1[\$]* *(?=\n|$)|$)/;
return [
{
name: "latexcode",
level: "inline",
start(src) {
return src.match(/\$/)?.index;
},
tokenizer(src, tokens) {
const cap = inlineRule.exec(src);
if (cap) {
let text = cap[2].replace(/\n/g, " ");
const hasNonSpaceChars = /[^ ]/.test(text);
const hasSpaceCharsOnBothEnds = /^ /.test(text) && / $/.test(text);
if (hasNonSpaceChars && hasSpaceCharsOnBothEnds) {
text = text.substring(1, text.length - 1);
}
return { type: "latexcode", raw: cap[0], text };
}
},
renderer(token) {
return tex`${token.text}`.outerHTML;
}
},
{
name: "latexblock",
level: "block",
start(src) {
return src.match(/\${2}/)?.index;
},
tokenizer(src, tokens) {
const cap = blockRule.exec(src);
if (cap) {
const raw = cap[0];
const text = indentLatexCompensation(raw, cap[2] || "");
return { type: "latexblock", raw, text };
}
},
renderer(token) {
return tex.block`${token.text}`.outerHTML;
}
}
];
}