fraudTech commited on
Commit
db9109f
·
1 Parent(s): cc6fa54

Reverted to the minimal preprocessing

Browse files
Files changed (1) hide show
  1. web/src/App.tsx +3 -65
web/src/App.tsx CHANGED
@@ -118,71 +118,9 @@ function preprocessMathContent(content: string): string {
118
 
119
  let processed = content;
120
 
121
- // Debug log to see what we're processing
122
- console.log('Original content:', content.substring(0, 200));
123
-
124
- // Step 1: Protect code blocks
125
- const codeBlocks: string[] = [];
126
- processed = processed.replace(/```[\s\S]*?```/g, (match) => {
127
- codeBlocks.push(match);
128
- return `___CODE_BLOCK_${codeBlocks.length - 1}___`;
129
- });
130
-
131
- // Step 2: Protect inline code
132
- const inlineCode: string[] = [];
133
- processed = processed.replace(/`[^`]+`/g, (match) => {
134
- inlineCode.push(match);
135
- return `___INLINE_CODE_${inlineCode.length - 1}___`;
136
- });
137
-
138
- // Step 3: Fix malformed delimiter patterns FIRST
139
- // $[ ... ]$ -> $$...$$ (display math)
140
- processed = processed.replace(/\$\[\s*/g, '$$');
141
- processed = processed.replace(/\s*\]\$/g, '$$');
142
-
143
- // Step 4: Protect properly formed math delimiters
144
- const existingMath: string[] = [];
145
- processed = processed.replace(/\$\$[\s\S]+?\$\$|\$[^\$\n]+?\$/g, (match) => {
146
- existingMath.push(match);
147
- return `___EXISTING_MATH_${existingMath.length - 1}___`;
148
- });
149
-
150
- // Step 5: Wrap LaTeX environments
151
- processed = processed.replace(/\\begin\{(equation|align|cases|matrix|pmatrix|bmatrix|array|split|gather)\}[\s\S]*?\\end\{\1\}/g, (match) => {
152
- return `$$${match}$$`;
153
- });
154
-
155
- // Step 6: Wrap complete fractions (both args present)
156
- processed = processed.replace(/\\(?:frac|tfrac|dfrac|cfrac)\s*\{[^}]*\}\s*\{[^}]*\}/g, (match) => `$${match}$`);
157
-
158
- // Step 7: Wrap incomplete fractions like \frac{d} or \frac{d}dx by fixing them
159
- // This handles cases where spacing breaks the pattern
160
- processed = processed.replace(/\\frac\s*\{([^}]*)\}\s*([a-zA-Z]+)/g, (_match, num, den) => {
161
- return `$\\frac{${num}}{${den}}$`;
162
- });
163
-
164
- // Step 8: Wrap standalone LaTeX commands
165
- processed = processed.replace(/\\(alpha|beta|gamma|delta|epsilon|zeta|eta|theta|iota|kappa|lambda|mu|nu|xi|pi|rho|sigma|tau|upsilon|phi|chi|psi|omega|Gamma|Delta|Theta|Lambda|Xi|Pi|Sigma|Upsilon|Phi|Psi|Omega|infty|partial|nabla|cdot|times|div|pm|mp|leq|geq|neq|approx|equiv|sum|prod|int|oint|lim|sqrt|sin|cos|tan|ln|log|exp|to|rightarrow|leftarrow|Rightarrow|Leftarrow|forall|exists|mathbb|mathbf|mathrm|text)\b/g, (match) => `$${match}$`);
166
-
167
- // Step 9: Wrap superscripts and subscripts
168
- processed = processed.replace(/([a-zA-Z0-9]+)([\^_])(\{[^}]+\}|[a-zA-Z0-9]+)/g, (match) => `$${match}$`);
169
-
170
- // Step 10: Wrap parentheses/brackets with backslash commands
171
- processed = processed.replace(/[\(\[]([^()\[\]]*\\[a-zA-Z]+[^()\[\]]*)[\)\]]/g, (match) => `$${match}$`);
172
-
173
- // Step 11: Clean up currency
174
- processed = processed.replace(/\$(\d+(?:\.\d{2})?)\$/g, '\\$$1');
175
-
176
- // Step 12: Merge adjacent math delimiters
177
- processed = processed.replace(/\$\s*\$/g, ' ');
178
- processed = processed.replace(/\$([^$]+)\$\s*\$([^$]+)\$/g, '$$$1 $2$$');
179
-
180
- // Step 13: Restore protected content
181
- processed = processed.replace(/___EXISTING_MATH_(\d+)___/g, (_, index) => existingMath[parseInt(index)]);
182
- processed = processed.replace(/___CODE_BLOCK_(\d+)___/g, (_, index) => codeBlocks[parseInt(index)]);
183
- processed = processed.replace(/___INLINE_CODE_(\d+)___/g, (_, index) => inlineCode[parseInt(index)]);
184
-
185
- console.log('Processed content:', processed.substring(0, 200));
186
 
187
  return processed;
188
  }
 
118
 
119
  let processed = content;
120
 
121
+ // Only protect currency amounts from being parsed as math
122
+ // Replace $number with \$number (unless already escaped)
123
+ processed = processed.replace(/(?<!\\)\$(\d+(?:\.\d{2})?)/g, '\\$$1');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
 
125
  return processed;
126
  }