From 80da856402d8471c03bdad2d6ef13c8a8a6c3f8d Mon Sep 17 00:00:00 2001 From: Daniel Roe Date: Mon, 16 Jan 2023 20:41:37 +0000 Subject: [PATCH] fix: handle parsing pure plain text --- composables/content-parse.ts | 2 +- tests/__snapshots__/content-rich.test.ts.snap | 5 +++++ tests/content-rich.test.ts | 5 +++++ 3 files changed, 11 insertions(+), 1 deletion(-) 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

')