fix: handle parsing pure plain text

This commit is contained in:
Daniel Roe 2023-01-16 20:41:37 +00:00
parent c4c15cf1c2
commit 80da856402
3 changed files with 11 additions and 1 deletions

View file

@ -451,7 +451,7 @@ function transformCollapseMentions() {
} }
return (node: Node, root: Node): Node | Node[] => { return (node: Node, root: Node): Node | Node[] => {
if (processed || node.parent !== root) if (processed || node.parent !== root || !node.children)
return node return node
const metions: (Node | undefined)[] = [] const metions: (Node | undefined)[] = []
const children = node.children as Node[] const children = node.children as Node[]

View file

@ -153,6 +153,11 @@ exports[`content-rich > link + mention 1`] = `
" "
`; `;
exports[`content-rich > plain text 1`] = `
"hello there
"
`;
exports[`editor > transform mentions 1`] = ` exports[`editor > transform mentions 1`] = `
" "
@elk Hello" @elk Hello"

View file

@ -11,6 +11,11 @@ describe('content-rich', () => {
expect(formatted).toMatchSnapshot() expect(formatted).toMatchSnapshot()
}) })
it('plain text', async () => {
const { formatted } = await render('hello there', { collapseMentionLink: true })
expect(formatted).toMatchSnapshot()
})
it('link + mention', async () => { it('link + mention', async () => {
// https://fosstodon.org/@ayo/109383002937620723 // https://fosstodon.org/@ayo/109383002937620723
const { formatted } = await render('<p>Happy 🤗 were now using <span class="h-card"><a href="https://webtoo.ls/@vitest" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>vitest</span></a></span> (migrated from chai+mocha) <a href="https://github.com/ayoayco/astro-reactive-library/pull/203" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/ayoayco/astro-react</span><span class="invisible">ive-library/pull/203</span></a></p>') const { formatted } = await render('<p>Happy 🤗 were now using <span class="h-card"><a href="https://webtoo.ls/@vitest" class="u-url mention" rel="nofollow noopener noreferrer" target="_blank">@<span>vitest</span></a></span> (migrated from chai+mocha) <a href="https://github.com/ayoayco/astro-reactive-library/pull/203" rel="nofollow noopener noreferrer" target="_blank"><span class="invisible">https://</span><span class="ellipsis">github.com/ayoayco/astro-react</span><span class="invisible">ive-library/pull/203</span></a></p>')