From 1da7b6ab6b55c79513e80dd5a1dbd2e8dc9a468f Mon Sep 17 00:00:00 2001 From: Rob Figueiredo Date: Sat, 21 Oct 2023 20:56:22 -0400 Subject: [PATCH] markdown: support formatting that extends to sibling nodes --- packages/lexical-markdown/src/MarkdownExport.ts | 5 +++-- .../src/__tests__/unit/LexicalMarkdown.test.ts | 4 ++++ 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/packages/lexical-markdown/src/MarkdownExport.ts b/packages/lexical-markdown/src/MarkdownExport.ts index c0215cdc626..31f84ee178e 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 2bc0891c0dc..93661828249 100644 --- a/packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts +++ b/packages/lexical-markdown/src/__tests__/unit/LexicalMarkdown.test.ts @@ -123,6 +123,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',