feat: display embedded media player (#2417)

This commit is contained in:
Ayo Ayco 2023-11-07 10:57:44 +01:00 committed by GitHub
parent 0bd1209bee
commit 957f0d3b17
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 146 additions and 5 deletions

View file

@ -150,6 +150,25 @@ export function convertMastodonHTML(html: string, customEmojis: Record<string, m
return render(tree)
}
export function sanitizeEmbeddedIframe(html: string): Node {
const transforms: Transform[] = [
sanitize({
iframe: {
src: (src) => {
if (typeof src !== 'string')
return undefined
const url = new URL(src)
return url.protocol === 'https:' ? src : undefined
},
allowfullscreen: set('true'),
},
}),
]
return transformSync(parse(html), transforms)
}
export function htmlToText(html: string) {
try {
const tree = parse(html)