Spaces:
Running
Running
Priyanshi Saxena
commited on
Commit
·
e142284
1
Parent(s):
43c3569
Fix JavaScript regex syntax error
Browse files- Simplified fallback markdown processing to avoid complex regex patterns
- Removed problematic regex patterns that caused 'Invalid regular expression' error
- Kept essential formatting (bold, italic, code, line breaks)
- This should resolve the frontend status check issue
app.py
CHANGED
@@ -1371,51 +1371,22 @@ async def get_homepage(request: Request):
|
|
1371 |
throw new Error('marked.js not available');
|
1372 |
}
|
1373 |
} catch (error) {
|
1374 |
-
//
|
1375 |
-
console.warn('Markdown parsing failed, using
|
1376 |
formattedContent = content
|
1377 |
-
|
1378 |
-
.replace(/\n\n/g, '</p><p>')
|
1379 |
.replace(/\n/g, '<br>')
|
1380 |
-
|
1381 |
-
.replace(
|
1382 |
-
.replace(
|
1383 |
-
|
1384 |
-
// Bold and italic
|
1385 |
-
.replace(/\\*\\*(.*?)\\*\\*/g, '<strong>$1</strong>')
|
1386 |
-
.replace(/\\*(.*?)\\*/g, '<em>$1</em>')
|
1387 |
-
// Code blocks
|
1388 |
-
.replace(/```([\\s\\S]*?)```/g, '<pre><code>$1</code></pre>')
|
1389 |
-
.replace(/`(.*?)`/g, '<code>$1</code>')
|
1390 |
-
// Lists
|
1391 |
-
.replace(/^\\* (.*$)/gm, '<li>$1</li>')
|
1392 |
-
.replace(/^\\- (.*$)/gm, '<li>$1</li>')
|
1393 |
-
.replace(/^(\\d+)\\. (.*$)/gm, '<li>$1. $2</li>')
|
1394 |
-
// Links
|
1395 |
-
.replace(/\\[([^\\]]+)\\]\\(([^)]+)\\)/g, '<a href="$2" target="_blank">$1</a>')
|
1396 |
-
// Blockquotes
|
1397 |
-
.replace(/^> (.*$)/gm, '<blockquote>$1</blockquote>')
|
1398 |
-
// Highlight crypto values (numbers with $ or crypto symbols)
|
1399 |
-
.replace(/(\\$[\\d,]+\\.?\\d*)/g, '<span class="crypto-value">$1</span>')
|
1400 |
-
.replace(/(\\d+\\.?\\d*\\s*(BTC|ETH|USD|USDC|USDT|SOL|ADA|DOT|LINK|UNI))/gi, '<span class="crypto-value">$1</span>')
|
1401 |
-
// Wrap in paragraph tags
|
1402 |
-
.replace(/^(?!<[^>]+>)(.+)$/gm, '<p>$1</p>')
|
1403 |
-
// Clean up empty paragraphs and fix list formatting
|
1404 |
-
.replace(/<p><\\/p>/g, '')
|
1405 |
-
.replace(/<p>(<li>.*<\\/li>)<\\/p>/g, '<ul>$1</ul>')
|
1406 |
-
.replace(/<\\/li><li>/g, '</li><li>')
|
1407 |
-
.replace(/<ul>(<li>.*)<\\/ul>/g, '<ul>$1</ul>');
|
1408 |
-
|
1409 |
-
// Post-process to add highlighting for important sections
|
1410 |
-
formattedContent = formattedContent
|
1411 |
-
.replace(/(Key.*?:|Important.*?:|Note.*?:|Summary.*?:|Conclusion.*?:)/gi, '<span class="highlight">$1</span>');
|
1412 |
}
|
1413 |
} else {
|
1414 |
-
//
|
1415 |
formattedContent = content
|
1416 |
-
.replace(
|
1417 |
-
.replace(
|
1418 |
-
.replace(
|
1419 |
.replace(/`(.*?)`/g, '<code>$1</code>');
|
1420 |
}
|
1421 |
|
|
|
1371 |
throw new Error('marked.js not available');
|
1372 |
}
|
1373 |
} catch (error) {
|
1374 |
+
// Simple fallback formatting if marked.js fails
|
1375 |
+
console.warn('Markdown parsing failed, using simple fallback:', error);
|
1376 |
formattedContent = content
|
1377 |
+
.replace(/\n\n/g, '<br><br>')
|
|
|
1378 |
.replace(/\n/g, '<br>')
|
1379 |
+
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
1380 |
+
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
1381 |
+
.replace(/`(.*?)`/g, '<code>$1</code>');
|
1382 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1383 |
}
|
1384 |
} else {
|
1385 |
+
// Simple user message formatting
|
1386 |
formattedContent = content
|
1387 |
+
.replace(/\n/g, '<br>')
|
1388 |
+
.replace(/\*\*(.*?)\*\*/g, '<strong>$1</strong>')
|
1389 |
+
.replace(/\*(.*?)\*/g, '<em>$1</em>')
|
1390 |
.replace(/`(.*?)`/g, '<code>$1</code>');
|
1391 |
}
|
1392 |
|