fix: the complex regexp caused node.js process to hang

Co-authored-by:  Claude 3 opus
This commit is contained in:
Yanlong Wang 2024-05-05 16:29:39 +08:00
parent fef1d0faf1
commit 2e025d10cf
No known key found for this signature in database
GPG Key ID: C0A623C0BADF9F37
3 changed files with 3 additions and 7 deletions

View File

@ -27,7 +27,3 @@ process.on('uncaughtException', (err) => {
console.error('Uncaught exception, process quit.');
throw err;
});
if (!process.env.FUNCTIONS_EMULATOR) {
registry.walk_around_firebase_stall = true;
}

View File

@ -2,14 +2,14 @@
export function tidyMarkdown(markdown: string): string {
// Step 1: Handle complex broken links with text and optional images spread across multiple lines
let normalizedMarkdown = markdown.replace(/\[\s*([^]+?)\s*\]\s*\(\s*([^)]+)\s*\)/g, (match, text, url) => {
let normalizedMarkdown = markdown.replace(/\[\s*([^\]\n]+?)\s*\]\s*\(\s*([^)]+)\s*\)/g, (match, text, url) => {
// Remove internal new lines and excessive spaces within the text
text = text.replace(/\s+/g, ' ').trim();
url = url.replace(/\s+/g, '').trim();
return `[${text}](${url})`;
});
normalizedMarkdown = normalizedMarkdown.replace(/\[\s*([^!]*?)\s*\n*(?:!\[([^\]]*)\]\((.*?)\))?\s*\n*\]\s*\(\s*([^)]+)\s*\)/g, (match, text, alt, imgUrl, linkUrl) => {
normalizedMarkdown = normalizedMarkdown.replace(/\[\s*([^\]\n!]*?)\s*\n*(?:!\[([^\]]*)\]\((.*?)\))?\s*\n*\]\s*\(\s*([^)]+)\s*\)/g, (match, text, alt, imgUrl, linkUrl) => {
// Normalize by removing excessive spaces and new lines
text = text.replace(/\s+/g, ' ').trim();
alt = alt ? alt.replace(/\s+/g, ' ').trim() : '';

@ -1 +1 @@
Subproject commit 21e6ece0f378fe26db888bc5ff7715a43bf022bd
Subproject commit d3bb3a7335ec9d96c68d1edf1b66fdf5e2fe5b7c