MCPcopy Create free account
hub / github.com/anomalyco/opencode / extractTextFromHTML

Function extractTextFromHTML

packages/core/src/tool/webfetch.ts:189–206  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

187})
188
189export 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
208export function convertHTMLToMarkdown(html: string) {
209 const turndown = new TurndownService({

Callers 1

convertFunction · 0.70

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected