diff --git a/.changeset/fix-math-in-color.md b/.changeset/fix-math-in-color.md new file mode 100644 index 000000000..cb09b6eeb --- /dev/null +++ b/.changeset/fix-math-in-color.md @@ -0,0 +1,5 @@ +--- +default: patch +--- + +Fix math parsing inside of color blocks not being parsed properly. diff --git a/src/app/plugins/markdown/extensions/matrix-math.ts b/src/app/plugins/markdown/extensions/matrix-math.ts index 21265f70f..26248a0b8 100644 --- a/src/app/plugins/markdown/extensions/matrix-math.ts +++ b/src/app/plugins/markdown/extensions/matrix-math.ts @@ -221,12 +221,18 @@ function isIgnorableMathContent(latex: string): boolean { * - the closing `$` is not preceded by whitespace, and * - the closing `$` is not immediately followed by an ASCII digit. */ +/** Opening `$[fg.color=…]` / `$[bg.color=…]` */ +const MFM_COLOR_FN_OPEN = /^\$\[(?:fg|bg)\.color=/; + function tryTokenizeInlineMath( src: string ): { type: 'math'; raw: string; latex: string } | undefined { if (!src.startsWith('$')) { return undefined; } + if (MFM_COLOR_FN_OPEN.test(src)) { + return undefined; + } if (src.startsWith('$$') && (src.length < 3 || src.charAt(2) !== '$')) { return undefined; } @@ -256,7 +262,7 @@ export const matrixMathExtension = { name: 'math', level: 'inline', start(src: string) { - if (/^\$\[(?:fg|bg)\.color=/.test(src)) return -1; + if (MFM_COLOR_FN_OPEN.test(src)) return -1; return src.indexOf('$'); }, tokenizer(src: string) {