fix: handle parsing pure plain text

pull/1177/head
Daniel Roe 2023-01-16 20:41:37 +00:00
rodzic c4c15cf1c2
commit 80da856402
3 zmienionych plików z 11 dodań i 1 usunięć

Wyświetl plik

@ -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[]

Wyświetl plik

@ -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"

Wyświetl plik

@ -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('<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>')