[Breaking Change][lexical-markdown] Bug Fix: Preserve paragraph separation after block elements (#7386)

This commit is contained in:
Kiran Dash
2025-03-28 00:17:45 +08:00
committed by GitHub
parent 74efb1df70
commit 680e23d2b0
2 changed files with 7 additions and 4 deletions

View File

@ -79,6 +79,7 @@ export function createMarkdownImport(
byType.element,
textFormatTransformersIndex,
byType.textMatch,
shouldPreserveNewLines,
);
}
@ -224,6 +225,7 @@ function $importBlocks(
elementTransformers: Array<ElementTransformer>,
textFormatTransformersIndex: TextFormatTransformersIndex,
textMatchTransformers: Array<TextMatchTransformer>,
shouldPreserveNewLines: boolean,
) {
const textNode = $createTextNode(lineText);
const elementNode = $createParagraphNode();
@ -253,9 +255,10 @@ function $importBlocks(
if (elementNode.isAttached() && lineText.length > 0) {
const previousNode = elementNode.getPreviousSibling();
if (
$isParagraphNode(previousNode) ||
$isQuoteNode(previousNode) ||
$isListNode(previousNode)
!shouldPreserveNewLines && // Only append if we're not preserving newlines
($isParagraphNode(previousNode) ||
$isQuoteNode(previousNode) ||
$isListNode(previousNode))
) {
let targetNode: typeof previousNode | ListItemNode | null = previousNode;

View File

@ -381,7 +381,7 @@ describe('Markdown', () => {
shouldMergeAdjacentLines: false,
},
{
html: '<p><span style="white-space: pre-wrap;">hello</span><br><span style="white-space: pre-wrap;">world</span></p>',
html: '<p><span style="white-space: pre-wrap;">hello</span></p><p><span style="white-space: pre-wrap;">world</span></p>',
md: 'hello\nworld',
shouldPreserveNewLines: true,
},