| 187 | }) |
| 188 | |
| 189 | export function extractTextFromHTML(html: string) { |
| 190 | let text = "" |
| 191 | let skipDepth = 0 |
| 192 | const parser = new Parser({ |
| 193 | onopentag(name) { |
| 194 | if (skipDepth > 0 || ["script", "style", "noscript", "iframe", "object", "embed"].includes(name)) skipDepth++ |
| 195 | }, |
| 196 | ontext(input) { |
| 197 | if (skipDepth === 0) text += input |
| 198 | }, |
| 199 | onclosetag() { |
| 200 | if (skipDepth > 0) skipDepth-- |
| 201 | }, |
| 202 | }) |
| 203 | parser.write(html) |
| 204 | parser.end() |
| 205 | return text.trim() |
| 206 | } |
| 207 | |
| 208 | export function convertHTMLToMarkdown(html: string) { |
| 209 | const turndown = new TurndownService({ |