MCPcopy Index your code
hub / github.com/simstudioai/sim / extractTextFromHtml

Function extractTextFromHtml

apps/sim/lib/mothership/inbox/format.ts:139–160  ·  view source on GitHub ↗

* Basic HTML to text extraction.

(html: string | null)

Source from the content-addressed store, hash-verified

137 * Basic HTML to text extraction.
138 */
139function extractTextFromHtml(html: string | null): string | null {
140 if (!html) return null
141
142 let text = html
143
144 text = decodeHtmlEntities(text)
145
146 text = replaceUntilStable(text, /<style[^>]*>[\s\S]*?<\/style\s*>/gi, '')
147 text = replaceUntilStable(text, /<script[^>]*>[\s\S]*?<\/script\s*>/gi, '')
148
149 text = text
150 .replace(/<br\s*\/?>/gi, '\n')
151 .replace(/<\/p>/gi, '\n\n')
152 .replace(/<\/div>/gi, '\n')
153 .replace(/<\/li>/gi, '\n')
154
155 text = replaceUntilStable(text, /<[^>]+>/g, '')
156
157 text = text.replace(/\n{3,}/g, '\n\n').trim()
158
159 return text
160}

Callers 1

formatEmailAsMessageFunction · 0.85

Calls 3

replaceUntilStableFunction · 0.85
decodeHtmlEntitiesFunction · 0.70
replaceMethod · 0.65

Tested by

no test coverage detected