Convert 12 JavaScript files to TypeScript (#57575)
This commit is contained in:
@@ -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()
|
||||
}
|
||||
Reference in New Issue
Block a user