Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/fix-math-in-color.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
default: patch
---

Fix math parsing inside of color blocks not being parsed properly.
8 changes: 7 additions & 1 deletion src/app/plugins/markdown/extensions/matrix-math.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand Down
Loading