1
0
mirror of synced 2025-12-19 18:10:59 -05:00

Convert 12 JavaScript files to TypeScript (#57575)

This commit is contained in:
Kevin Heis
2025-09-19 11:57:12 -07:00
committed by GitHub
parent f313d7bcc0
commit a91e77679a
16 changed files with 200 additions and 95 deletions

View File

@@ -7,11 +7,12 @@ import { decode } from 'html-entities'
// Take advantage of the subtle fact that a lot of the times, the html value
// we get here is a single line that starts with `<p>` and ends with `</p>`
// and contains no longer HTML tags.
export function fastTextOnly(html) {
export function fastTextOnly(html: string): string {
if (!html) return ''
if (html.startsWith('<p>') && html.endsWith('</p>')) {
const middle = html.slice(3, -4)
if (!middle.includes('<')) return decode(middle.trim())
}
return cheerio.load(html, { xmlMode: true }).text().trim()
const $ = cheerio.load(html, { xmlMode: true })
return $.root().text().trim()
}