feat: hide redudant mentions (#1293)

This commit is contained in:
patak 2023-01-18 16:59:37 +01:00 committed by GitHub
parent da2f19fb23
commit 3132f4fdea
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 186 additions and 30 deletions

View file

@ -1,7 +1,7 @@
import type { mastodon } from 'masto'
import { describe, expect, it } from 'vitest'
import { format } from 'prettier'
import { render as renderTree } from 'ultrahtml'
import type { ContentParseOptions } from '~~/composables/content-parse'
describe('html-parse', () => {
it('empty', async () => {
@ -19,11 +19,13 @@ describe('html-parse', () => {
it('custom emoji', async () => {
const { formatted, serializedText } = await render('Daniel Roe :nuxt:', {
nuxt: {
shortcode: 'nuxt',
url: 'https://media.webtoo.ls/custom_emojis/images/000/000/366/original/73330dfc9dda4078.png',
staticUrl: 'https://media.webtoo.ls/custom_emojis/images/000/000/366/original/73330dfc9dda4078.png',
visibleInPicker: true,
emojis: {
nuxt: {
shortcode: 'nuxt',
url: 'https://media.webtoo.ls/custom_emojis/images/000/000/366/original/73330dfc9dda4078.png',
staticUrl: 'https://media.webtoo.ls/custom_emojis/images/000/000/366/original/73330dfc9dda4078.png',
visibleInPicker: true,
},
},
})
expect(formatted).toMatchSnapshot('html')
@ -62,8 +64,8 @@ describe('html-parse', () => {
})
})
async function render(input: string, emojis?: Record<string, mastodon.v1.CustomEmoji>) {
const tree = parseMastodonHTML(input, { emojis })
async function render(input: string, options?: ContentParseOptions) {
const tree = parseMastodonHTML(input, options)
const html = await renderTree(tree)
let formatted = ''
const serializedText = treeToText(tree).trim()