fix: decode numerically encoded html entities in text

This commit is contained in:
Daniel Roe 2022-12-05 00:15:17 +00:00
parent 408aff20ee
commit 4146915a33
No known key found for this signature in database
GPG key ID: 22D5008E4F5D9B55
2 changed files with 5 additions and 3 deletions

View file

@ -72,7 +72,9 @@ export function parseMastodonHTML(html: string, customEmojis: Record<string, Emo
[/\*(.*?)\*/g, '<em>$1</em>'],
[/~~(.*?)~~/g, '<del>$1</del>'],
[/`([^`]+?)`/g, '<code>$1</code>'],
] as const
[/&#(\d+);/g, (_: string, dec: string) => String.fromCharCode(Number(dec))],
] as any
for (const [re, replacement] of replacements) {
for (const match of node.value.matchAll(re)) {
if (node.loc) {

View file

@ -1,7 +1,7 @@
// Vitest Snapshot v1
exports[`html-parse > code frame > html 1`] = `
"<p>Testing code block</p><p><pre><code class=\\"language-ts\\">import { useMouse, usePreferredDark } from &#39;@vueuse/core&#39;
"<p>Testing code block</p><p><pre><code class=\\"language-ts\\">import { useMouse, usePreferredDark } from '@vueuse/core'
// tracks mouse position
const { x, y } = useMouse()
// is the user prefers dark theme
@ -12,7 +12,7 @@ exports[`html-parse > code frame > text 1`] = `
"Testing code block
\`\`\`ts
import { useMouse, usePreferredDark } from &#39;@vueuse/core&#39;
import { useMouse, usePreferredDark } from '@vueuse/core'
// tracks mouse position
const { x, y } = useMouse()
// is the user prefers dark theme