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

View File

@ -381,7 +381,7 @@ describe('Markdown', () => {
shouldMergeAdjacentLines: false, 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', md: 'hello\nworld',
shouldPreserveNewLines: true, shouldPreserveNewLines: true,
}, },