diff --git a/packages/lexical-markdown/src/MarkdownExport.ts b/packages/lexical-markdown/src/MarkdownExport.ts index 9423f839f1c0..1f4c559e3529 100644 --- a/packages/lexical-markdown/src/MarkdownExport.ts +++ b/packages/lexical-markdown/src/MarkdownExport.ts @@ -14,6 +14,7 @@ import type { } from '@lexical/markdown'; import type {ElementNode, LexicalNode, TextFormatType, TextNode} from 'lexical'; +import {$isLinkNode} from '@lexical/link'; import { $getRoot, $isDecoratorNode, @@ -176,7 +177,7 @@ function getTextSibling(node: TextNode, backward: boolean): TextNode | null { if (!sibling) { const parent = node.getParentOrThrow(); - if (parent.isInline()) { + if (parent.isInline() && !$isLinkNode(parent)) { sibling = backward ? parent.getPreviousSibling() : parent.getNextSibling(); @@ -185,7 +186,7 @@ function getTextSibling(node: TextNode, backward: boolean): TextNode | null { while (sibling) { if ($isElementNode(sibling)) { - if (!sibling.isInline()) { + if (!sibling.isInline() || $isLinkNode(sibling)) { break; } diff --git a/packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts b/packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts index a4aeb7ba7d5e..4623b6cec6d2 100644 --- a/packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts +++ b/packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts @@ -117,6 +117,10 @@ describe('Markdown', () => { html: '

Hello XXX world

', md: 'Hello [`XXX`](https://lexical.dev) world', }, + { + html: '

Hello XXY

', + md: '`Hello` [`XXY`](https://lexical.dev)', + }, { html: '

Hello world

', md: '~~Hello~~ world',