(html: string)
| 137 | } |
| 138 | |
| 139 | function 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 | |
| 157 | function extractMetaContent(html: string, name: string): string | undefined { |
| 158 | const escapedName = name.replace(/[.*+?^${}()|[\]\\]/g, '\\$&') |
no test coverage detected