MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / selectReadableHtml

Function selectReadableHtml

sdk/src/tools/read-url.ts:139–155  ·  view source on GitHub ↗
(html: string)

Source from the content-addressed store, hash-verified

137}
138
139function selectReadableHtml(html: string): string {
140 const articleCandidates = extractElementContents(html, 'article')
141 if (articleCandidates.length > 0) {
142 return articleCandidates.reduce((best, candidate) =>
143 stripTags(candidate).length > stripTags(best).length ? candidate : best,
144 )
145 }
146
147 const mainCandidates = extractElementContents(html, 'main')
148 if (mainCandidates.length > 0) {
149 return mainCandidates.reduce((best, candidate) =>
150 stripTags(candidate).length > stripTags(best).length ? candidate : best,
151 )
152 }
153
154 return html
155}
156
157function extractMetaContent(html: string, name: string): string | undefined {
158 const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&')

Callers 1

extractHtmlFunction · 0.85

Calls 2

extractElementContentsFunction · 0.85
stripTagsFunction · 0.85

Tested by

no test coverage detected