fix: decode other entity text as well

zio/stable
Daniel Roe 2022-12-05 00:30:20 +00:00
parent 4146915a33
commit 09290b112e
No known key found for this signature in database
GPG Key ID: 22D5008E4F5D9B55
1 changed files with 7 additions and 1 deletions

View File

@ -43,6 +43,12 @@ function handleNode(el: Node) {
return handleCodeBlock(el) || handleMention(el) || el
}
const decoder = document.createElement('textarea')
function decode(text: string) {
decoder.innerHTML = text
return decoder.value
}
/**
* Parse raw HTML form Mastodon server to AST,
* with interop of custom emojis and inline Markdown syntax
@ -72,7 +78,7 @@ export function parseMastodonHTML(html: string, customEmojis: Record<string, Emo
[/\*(.*?)\*/g, '<em>$1</em>'],
[/~~(.*?)~~/g, '<del>$1</del>'],
[/`([^`]+?)`/g, '<code>$1</code>'],
[/&#(\d+);/g, (_: string, dec: string) => String.fromCharCode(Number(dec))],
[/&[^;]+;/g, (val: string) => decode(val)],
] as any
for (const [re, replacement] of replacements) {