MCPcopy Create free account
hub / github.com/garrytan/gstack / htmlToPlainText

Function htmlToPlainText

browse/src/security-classifier.ts:268–281  ·  view source on GitHub ↗

* Strip HTML tags and collapse whitespace. TestSavantAI was trained on * plain text, not markup — feeding it raw HTML massively reduces recall * because all the tag noise dilutes the injection signal. Callers that * already have plain text (page snapshot innerText, tool output strings) * get no-

(input: string)

Source from the content-addressed store, hash-verified

266 * get no-op behavior; callers with HTML get the markup stripped.
267 */
268function htmlToPlainText(input: string): string {
269 // Fast path: if no angle brackets, it's already plain text.
270 if (!input.includes('<')) return input;
271 return input
272 .replace(/<(script|style)[^>]*>[\s\S]*?<\/\1>/gi, ' ') // drop script/style bodies entirely
273 .replace(/<[^>]+>/g, ' ') // drop tags
274 .replace(/&nbsp;/g, ' ')
275 .replace(/&amp;/g, '&')
276 .replace(/&lt;/g, '<')
277 .replace(/&gt;/g, '>')
278 .replace(/&quot;/g, '"')
279 .replace(/\s+/g, ' ')
280 .trim();
281}
282
283export async function scanPageContent(text: string): Promise<LayerSignal> {
284 if (!text || text.length === 0) {

Callers 2

scanPageContentFunction · 0.85
scanPageContentDebertaFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected