feat: hide redudant mentions (#1293)
This commit is contained in:
parent
da2f19fb23
commit
3132f4fdea
9 changed files with 186 additions and 30 deletions
|
@ -92,6 +92,25 @@ exports[`html-parse > empty > html 1`] = `""`;
|
|||
|
||||
exports[`html-parse > empty > text 1`] = `""`;
|
||||
|
||||
exports[`html-parse > hide mentions in context > html 1`] = `
|
||||
"<p>
|
||||
<mention-group
|
||||
><span class=\\"h-card\\"
|
||||
><a
|
||||
href=\\"/@haoqun@webtoo.ls\\"
|
||||
class=\\"u-url mention\\"
|
||||
rel=\\"nofollow noopener noreferrer\\"
|
||||
target=\\"_blank\\"
|
||||
>@<span>haoqun</span></a
|
||||
></span
|
||||
></mention-group
|
||||
>Great to see this happening
|
||||
</p>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`html-parse > hide mentions in context > text 1`] = `"@haoqunGreat to see this happening"`;
|
||||
|
||||
exports[`html-parse > html entities > html 1`] = `
|
||||
"<p>Hello <World />.</p>
|
||||
"
|
||||
|
@ -142,3 +161,50 @@ exports[`html-parse > link + mention > html 1`] = `
|
|||
`;
|
||||
|
||||
exports[`html-parse > link + mention > text 1`] = `"Happy 🤗 we’re now using @vitest (migrated from chai+mocha) https://github.com/ayoayco/astro-reactive-library/pull/203"`;
|
||||
|
||||
exports[`html-parse > mentions without context > html 1`] = `
|
||||
"<p>
|
||||
<mention-group
|
||||
><span class=\\"h-card\\"
|
||||
><a
|
||||
href=\\"/@haoqun@webtoo.ls\\"
|
||||
class=\\"u-url mention\\"
|
||||
rel=\\"nofollow noopener noreferrer\\"
|
||||
target=\\"_blank\\"
|
||||
>@<span>haoqun</span></a
|
||||
></span
|
||||
></mention-group
|
||||
>Great to see this happening
|
||||
</p>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`html-parse > mentions without context > text 1`] = `"@haoqunGreat to see this happening"`;
|
||||
|
||||
exports[`html-parse > show mentions in context > html 1`] = `
|
||||
"<p>
|
||||
<mention-group
|
||||
><span class=\\"h-card\\"
|
||||
><a
|
||||
href=\\"/@haoqun@webtoo.ls\\"
|
||||
class=\\"u-url mention\\"
|
||||
rel=\\"nofollow noopener noreferrer\\"
|
||||
target=\\"_blank\\"
|
||||
>@<span>haoqun</span></a
|
||||
></span
|
||||
>
|
||||
<span class=\\"h-card\\"
|
||||
><a
|
||||
href=\\"/@antfu@webtoo.ls\\"
|
||||
class=\\"u-url mention\\"
|
||||
rel=\\"nofollow noopener noreferrer\\"
|
||||
target=\\"_blank\\"
|
||||
>@<span>antfu</span></a
|
||||
></span
|
||||
></mention-group
|
||||
>Great to see this happening
|
||||
</p>
|
||||
"
|
||||
`;
|
||||
|
||||
exports[`html-parse > show mentions in context > text 1`] = `"@haoqun @antfuGreat to see this happening"`;
|
||||
|
|
|
@ -2,6 +2,7 @@
|
|||
import { describe, expect, it, vi } from 'vitest'
|
||||
import { renderToString } from 'vue/server-renderer'
|
||||
import { format } from 'prettier'
|
||||
import type { mastodon } from 'masto'
|
||||
import { contentToVNode } from '~/composables/content-render'
|
||||
import type { ContentParseOptions } from '~~/composables/content-parse'
|
||||
|
||||
|
@ -139,6 +140,37 @@ describe('content-rich', () => {
|
|||
`)
|
||||
})
|
||||
|
||||
it('hides collapsed mentions', async () => {
|
||||
const { formatted } = await render('<p><span class="h-card"><a href="https://m.webtoo.ls/@elk" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>elk</span></a></span> content</p>', {
|
||||
collapseMentionLink: true,
|
||||
inReplyToStatus: { account: { acct: 'elk@webtoo.ls' }, mentions: [] as mastodon.v1.StatusMention[] } as mastodon.v1.Status,
|
||||
})
|
||||
expect(formatted).toMatchInlineSnapshot(`
|
||||
"<p>content</p>
|
||||
"
|
||||
`)
|
||||
})
|
||||
|
||||
it('shows some collapsed mentions', async () => {
|
||||
const { formatted } = await render('<p><span class="h-card"><a href="https://m.webtoo.ls/@elk" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>elk</span></a></span> <span class="h-card"><a href="https://m.webtoo.ls/@antfu" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>antfu</span></a></span> content</p>', {
|
||||
collapseMentionLink: true,
|
||||
inReplyToStatus: { account: { acct: 'elk@webtoo.ls' }, mentions: [] as mastodon.v1.StatusMention[] } as mastodon.v1.Status,
|
||||
})
|
||||
expect(formatted).toMatchInlineSnapshot(`
|
||||
"<p>
|
||||
<mention-group>
|
||||
<span class=\\"h-card\\"
|
||||
><a
|
||||
class=\\"u-url mention\\"
|
||||
rel=\\"nofollow noopener noreferrer\\"
|
||||
to=\\"/m.webtoo.ls/@antfu\\"
|
||||
></a></span></mention-group
|
||||
>content
|
||||
</p>
|
||||
"
|
||||
`)
|
||||
})
|
||||
|
||||
it ('block with injected html, without language', async () => {
|
||||
const { formatted } = await render(`
|
||||
<pre>
|
||||
|
|
|
@ -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()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue