refactor: html parsing

This commit is contained in:
Anthony Fu 2023-01-07 10:31:48 +01:00
parent d76e4bfaa5
commit 6944a74653
8 changed files with 152 additions and 124 deletions

View file

@ -1,9 +1,9 @@
import type { Emoji } from 'masto'
import { TEXT_NODE } from 'ultrahtml'
import type { Node } from 'ultrahtml'
import { Fragment, h, isVNode } from 'vue'
import type { VNode } from 'vue'
import { RouterLink } from 'vue-router'
import type { ContentParseOptions } from './content-parse'
import { decodeHtml, parseMastodonHTML } from './content-parse'
import ContentCode from '~/components/content/ContentCode.vue'
import AccountHoverWrapper from '~/components/account/AccountHoverWrapper.vue'
@ -13,12 +13,9 @@ import AccountHoverWrapper from '~/components/account/AccountHoverWrapper.vue'
*/
export function contentToVNode(
content: string,
{ emojis = {}, markdown = true }: {
emojis?: Record<string, Emoji>
markdown?: boolean
} = {},
options?: ContentParseOptions,
): VNode {
const tree = parseMastodonHTML(content, emojis, markdown)
const tree = parseMastodonHTML(content, options)
return h(Fragment, (tree.children as Node[]).map(n => treeToVNode(n)))
}