Spaces:
Sleeping
Sleeping
Updated math preprocessing to force display math delimiters onto their own lines so remark-math treats them as block math and KaTeX renders correctly.
Browse files
web/src/math-preprocessing.ts
CHANGED
|
@@ -56,8 +56,14 @@ export function preprocessMathContent(content: string): string {
|
|
| 56 |
if (trimmed.includes('\n')) {
|
| 57 |
return `$$\n${trimmed}\n$$\n`;
|
| 58 |
}
|
| 59 |
-
return `$$${trimmed}$$\n`;
|
| 60 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
// Step 7: Clean up multiple newlines
|
| 63 |
processed = processed.replace(/\n{3,}/g, '\n\n');
|
|
|
|
| 56 |
if (trimmed.includes('\n')) {
|
| 57 |
return `$$\n${trimmed}\n$$\n`;
|
| 58 |
}
|
| 59 |
+
return `$$\n${trimmed}\n$$\n`;
|
| 60 |
});
|
| 61 |
+
|
| 62 |
+
// Step 6.5: Ensure $$ delimiters are on their own lines
|
| 63 |
+
// Insert newline before $$ if it shares a line with other text
|
| 64 |
+
processed = processed.replace(/([^\n])\$\$/g, '$1\n$$');
|
| 65 |
+
// Insert newline after $$ if it shares a line with other text
|
| 66 |
+
processed = processed.replace(/\$\$([^\n])/g, '$$\n$1');
|
| 67 |
|
| 68 |
// Step 7: Clean up multiple newlines
|
| 69 |
processed = processed.replace(/\n{3,}/g, '\n\n');
|