diff --git a/composables/content-parse.ts b/composables/content-parse.ts index b113eaa1..9c0baf92 100644 --- a/composables/content-parse.ts +++ b/composables/content-parse.ts @@ -451,7 +451,7 @@ function transformCollapseMentions() { } return (node: Node, root: Node): Node | Node[] => { - if (processed || node.parent !== root) + if (processed || node.parent !== root || !node.children) return node const metions: (Node | undefined)[] = [] const children = node.children as Node[] diff --git a/tests/__snapshots__/content-rich.test.ts.snap b/tests/__snapshots__/content-rich.test.ts.snap index cd75bdac..289bfb73 100644 --- a/tests/__snapshots__/content-rich.test.ts.snap +++ b/tests/__snapshots__/content-rich.test.ts.snap @@ -153,6 +153,11 @@ exports[`content-rich > link + mention 1`] = ` " `; +exports[`content-rich > plain text 1`] = ` +"hello there +" +`; + exports[`editor > transform mentions 1`] = ` " @elk Hello" diff --git a/tests/content-rich.test.ts b/tests/content-rich.test.ts index f66021bd..67228ba7 100644 --- a/tests/content-rich.test.ts +++ b/tests/content-rich.test.ts @@ -11,6 +11,11 @@ describe('content-rich', () => { expect(formatted).toMatchSnapshot() }) + it('plain text', async () => { + const { formatted } = await render('hello there', { collapseMentionLink: true }) + expect(formatted).toMatchSnapshot() + }) + it('link + mention', async () => { // https://fosstodon.org/@ayo/109383002937620723 const { formatted } = await render('

Happy 🤗 we’re now using @vitest (migrated from chai+mocha) github.com/ayoayco/astro-react

')