diff --git a/src/tools/fetch/web-fetch-utils.ts b/src/tools/fetch/web-fetch-utils.ts index 39448c1..f1c8842 100644 --- a/src/tools/fetch/web-fetch-utils.ts +++ b/src/tools/fetch/web-fetch-utils.ts @@ -35,10 +35,15 @@ function normalizeWhitespace(value: string): string { export function htmlToMarkdown(html: string): { text: string; title?: string } { const titleMatch = html.match(/]*>([\s\S]*?)<\/title>/i); const title = titleMatch ? normalizeWhitespace(stripTags(titleMatch[1])) : undefined; - let text = html - .replace(//gi, "") - .replace(//gi, "") - .replace(//gi, ""); + let text = html; + let previous: string; + do { + previous = text; + text = text + .replace(//gi, "") + .replace(//gi, "") + .replace(//gi, ""); + } while (text !== previous); text = text.replace(/]*href=["']([^"']+)["'][^>]*>([\s\S]*?)<\/a>/gi, (_, href, body) => { const label = normalizeWhitespace(stripTags(body)); if (!label) {