mirror of
https://github.com/bewcloud/bewcloud.git
synced 2026-03-11 08:54:49 +00:00
fix: preserve single line breaks, only collapse 2+ consecutive whitespace
Address review feedback: the previous \s+ regex was too aggressive and broke text-only summaries with legitimate line breaks. Now: - Collapse runs of 2+ non-newline whitespace into a single space - Collapse 3+ consecutive newlines into double newline (paragraph break) - Single line breaks are preserved
This commit is contained in:
parent
2297ba8b4d
commit
7a3bfc50e7
1 changed files with 3 additions and 2 deletions
|
|
@ -232,8 +232,9 @@ export async function parseTextFromHtml(html: string): Promise<string> {
|
|||
|
||||
// Extract text from body to avoid any artifacts from the document wrapper
|
||||
const text = (document?.querySelector('body')?.textContent || document?.textContent || '')
|
||||
// Collapse multiple whitespace/newlines into single spaces
|
||||
.replace(/\s+/g, ' ')
|
||||
// Collapse runs of 2+ whitespace/newline characters, preserving single line breaks
|
||||
.replace(/[^\S\n]{2,}/g, ' ')
|
||||
.replace(/\n{3,}/g, '\n\n')
|
||||
.trim();
|
||||
|
||||
return text;
|
||||
|
|
|
|||
Loading…
Reference in a new issue