perf: replace parse5 with ultrahtml (#336)

This commit is contained in:
Daniel Roe 2022-12-04 22:10:10 +00:00 committed by GitHub
parent 04615e443e
commit 1c0f8b0147
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 94 additions and 143 deletions

View file

@ -1,7 +1,7 @@
import type { Emoji } from 'masto'
import { describe, expect, it } from 'vitest'
import { format } from 'prettier'
import { serialize } from 'parse5'
import { render as renderTree } from 'ultrahtml'
import { parseMastodonHTML, treeToText } from '~/composables/content'
describe('html-parse', () => {
@ -53,9 +53,9 @@ describe('html-parse', () => {
async function render(input: string, emojis?: Record<string, Emoji>) {
const tree = parseMastodonHTML(input, emojis)
const html = serialize(tree)
const html = await renderTree(tree)
let formatted = ''
const serializedText = tree.childNodes.map(n => treeToText(n)).join('').trim()
const serializedText = tree.children.map(n => treeToText(n)).join('').trim()
try {
formatted = format(html, {