| 156 | ) |
| 157 | |
| 158 | function extractTextFromHTML(html: string) { |
| 159 | let text = "" |
| 160 | let skipDepth = 0 |
| 161 | |
| 162 | const parser = new Parser({ |
| 163 | onopentag(name) { |
| 164 | if (skipDepth > 0 || ["script", "style", "noscript", "iframe", "object", "embed"].includes(name)) { |
| 165 | skipDepth++ |
| 166 | } |
| 167 | }, |
| 168 | ontext(input) { |
| 169 | if (skipDepth === 0) text += input |
| 170 | }, |
| 171 | onclosetag() { |
| 172 | if (skipDepth > 0) skipDepth-- |
| 173 | }, |
| 174 | }) |
| 175 | |
| 176 | parser.write(html) |
| 177 | parser.end() |
| 178 | |
| 179 | return text.trim() |
| 180 | } |
| 181 | |
| 182 | function convertHTMLToMarkdown(html: string): string { |
| 183 | const turndownService = new TurndownService({ |