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

Function extractTextFromHTML

packages/opencode/src/tool/webfetch.ts:158–180  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

156)
157
158function 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
182function convertHTMLToMarkdown(html: string): string {
183 const turndownService = new TurndownService({

Callers 1

webfetch.tsFile · 0.70

Calls 1

writeMethod · 0.80

Tested by

no test coverage detected