mirror of
https://github.com/bendtherules/ask262.git
synced 2026-08-18 21:31:46 +00:00
fix - Fix normalizeWhitespace removing indents in nested lists
This commit is contained in:
@@ -111,7 +111,7 @@ export class HTMLTextSplitter extends TextSplitter {
|
||||
...fields,
|
||||
chunkOverlap: 0,
|
||||
keepSeparator: false,
|
||||
lengthFunction: (text: string) => this.normalizeWhitespace(text).length,
|
||||
lengthFunction: (text: string) => text.trim().length,
|
||||
});
|
||||
|
||||
this.separators = fields?.separators ?? [];
|
||||
@@ -229,22 +229,6 @@ export class HTMLTextSplitter extends TextSplitter {
|
||||
return node.type === "tag" && BLOCKISH_TAGS.has(node.name);
|
||||
}
|
||||
|
||||
/**
|
||||
* Collapses internal whitespace and trims leading/trailing whitespace.
|
||||
* Preserves newlines between block elements while normalizing spaces.
|
||||
*
|
||||
* Needed so text extraction can preserve raw adjacency first and normalize
|
||||
* only once after boundary-aware joining.
|
||||
*/
|
||||
private normalizeWhitespace(text: string): string {
|
||||
return text
|
||||
.replace(/\n[ \t]+/g, "\n") // Remove leading spaces after newlines
|
||||
.replace(/[ \t]+\n/g, "\n") // Remove trailing spaces before newlines
|
||||
.replace(/\n{3,}/g, "\n\n") // Collapse 3+ newlines to 2
|
||||
.replace(/[ \t]{2,}/g, " ") // Collapse multiple spaces/tabs to one
|
||||
.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Joins multiple nodes into the normalized text the splitter actually emits.
|
||||
*
|
||||
@@ -273,7 +257,7 @@ export class HTMLTextSplitter extends TextSplitter {
|
||||
previousNode = node;
|
||||
}
|
||||
|
||||
return this.normalizeWhitespace(result);
|
||||
return result.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user