simplify inline tex parsing

This commit is contained in:
Eric Rykwalder 2022-03-09 17:40:50 -05:00
parent 82886ae675
commit 71bf70e4d3
2 changed files with 6 additions and 6 deletions

View file

@ -263,6 +263,8 @@ Line 5}
`
{P:plaintext {XI:{xm:$}tex content{xm:$}} more plaintext}
{P:plaintext {XI:{xm:$}tex content{xm:$}}more plaintext}
{P:{XI:{xm:$}1.234{xm:$}}}
`
);

View file

@ -429,16 +429,14 @@ export const Tex: MarkdownConfig = {
{
name: "TexInline",
parse(cx: InlineContext, next: number, pos: number) {
let match = /^\$[^$\s]/.exec(cx.text.slice(pos - cx.offset));
let match = /^\$(?:[^$\t ][^$]*)?[^$\t \\]\$(\D|$)/.exec(
cx.text.slice(pos - cx.offset)
);
if (!match) {
return -1;
}
const start = pos;
match = /[^\t \\]\$(\D|$)/.exec(cx.text.slice(pos - cx.offset + 1));
if (!match) {
return -1;
}
const end = start + 1 + match.index + 2;
const end = start + match[0].length - match[1].length;
return cx.addElement(
cx.elt("TexInline", start, end, [
cx.elt("TexMarker", start, start + 1),