chore: fix typo

This commit is contained in:
patak 2023-01-18 08:01:50 +01:00
parent 9c82df0a7a
commit 40c0afb09d
2 changed files with 7 additions and 7 deletions

View file

@ -453,16 +453,16 @@ function transformCollapseMentions() {
return (node: Node, root: Node): Node | Node[] => { return (node: Node, root: Node): Node | Node[] => {
if (processed || node.parent !== root || !node.children) if (processed || node.parent !== root || !node.children)
return node return node
const metions: (Node | undefined)[] = [] const mentions: (Node | undefined)[] = []
const children = node.children as Node[] const children = node.children as Node[]
for (const child of children) { for (const child of children) {
// metion // metion
if (isMention(child)) { if (isMention(child)) {
metions.push(child) mentions.push(child)
} }
// spaces in between // spaces in between
else if (child.type === TEXT_NODE && !child.value.trim()) { else if (child.type === TEXT_NODE && !child.value.trim()) {
metions.push(child) mentions.push(child)
} }
// other content, stop collapsing // other content, stop collapsing
else { else {
@ -470,17 +470,17 @@ function transformCollapseMentions() {
child.value = child.value.trimStart() child.value = child.value.trimStart()
// remove <br> after mention // remove <br> after mention
if (child.name === 'br') if (child.name === 'br')
metions.push(undefined) mentions.push(undefined)
break break
} }
} }
processed = true processed = true
if (metions.length === 0) if (mentions.length === 0)
return node return node
return { return {
...node, ...node,
children: [h('mention-group', null, ...metions.filter(Boolean)), ...children.slice(metions.length)], children: [h('mention-group', null, ...mentions.filter(Boolean)), ...children.slice(mentions.length)],
} }
} }
} }

View file

@ -84,7 +84,7 @@ describe('content-rich', () => {
expect(formatted).toMatchSnapshot() expect(formatted).toMatchSnapshot()
}) })
it('collapse metions', async () => { it('collapse 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/@elk" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>elk</span></a></span> content <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> <span class="h-card"><a href="https://mastodon.roe.dev/@daniel" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>daniel</span></a></span> <span class="h-card"><a href="https://m.webtoo.ls/@sxzz" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>sxzz</span></a></span> <span class="h-card"><a href="https://m.webtoo.ls/@patak" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>patak</span></a></span> content</p>', { 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/@elk" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>elk</span></a></span> content <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> <span class="h-card"><a href="https://mastodon.roe.dev/@daniel" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>daniel</span></a></span> <span class="h-card"><a href="https://m.webtoo.ls/@sxzz" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>sxzz</span></a></span> <span class="h-card"><a href="https://m.webtoo.ls/@patak" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>patak</span></a></span> content</p>', {
collapseMentionLink: true, collapseMentionLink: true,
}) })