Skip to content

Commit 19e3dbc

Browse files
authored
Fix math parsing in color (#910)
<!-- Please read https://github.com/SableClient/Sable/blob/dev/CONTRIBUTING.md before submitting your pull request --> ### Description <!-- Please include a summary of the change. Please also include relevant motivation and context. List any dependencies that are required for this change. --> Fixes math parsing inside of color blocks not being parsed as math with color. #### Type of change - [x] Bug fix (non-breaking change which fixes an issue) - [ ] New feature (non-breaking change which adds functionality) - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) - [ ] This change requires a documentation update ### Checklist: - [ ] My code follows the style guidelines of this project - [ ] I have performed a self-review of my own code - [ ] I have commented my code, particularly in hard-to-understand areas - [ ] I have made corresponding changes to the documentation - [ ] My changes generate no new warnings ### AI disclosure: - [ ] Partially AI assisted (clarify which code was AI assisted and briefly explain what it does). - [ ] Fully AI generated (explain what all the generated code does in moderate detail). <!-- Write any explanation required here, but do not generate the explanation using AI!! You must prove you understand what the code in this PR does. -->
2 parents d012f0a + b706cb9 commit 19e3dbc

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

.changeset/fix-math-in-color.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
default: patch
3+
---
4+
5+
Fix math parsing inside of color blocks not being parsed properly.

src/app/plugins/markdown/extensions/matrix-math.ts

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -221,12 +221,18 @@ function isIgnorableMathContent(latex: string): boolean {
221221
* - the closing `$` is not preceded by whitespace, and
222222
* - the closing `$` is not immediately followed by an ASCII digit.
223223
*/
224+
/** Opening `$[fg.color=…]` / `$[bg.color=…]` */
225+
const MFM_COLOR_FN_OPEN = /^\$\[(?:fg|bg)\.color=/;
226+
224227
function tryTokenizeInlineMath(
225228
src: string
226229
): { type: 'math'; raw: string; latex: string } | undefined {
227230
if (!src.startsWith('$')) {
228231
return undefined;
229232
}
233+
if (MFM_COLOR_FN_OPEN.test(src)) {
234+
return undefined;
235+
}
230236
if (src.startsWith('$$') && (src.length < 3 || src.charAt(2) !== '$')) {
231237
return undefined;
232238
}
@@ -256,7 +262,7 @@ export const matrixMathExtension = {
256262
name: 'math',
257263
level: 'inline',
258264
start(src: string) {
259-
if (/^\$\[(?:fg|bg)\.color=/.test(src)) return -1;
265+
if (MFM_COLOR_FN_OPEN.test(src)) return -1;
260266
return src.indexOf('$');
261267
},
262268
tokenizer(src: string) {

0 commit comments

Comments
 (0)