mirror of
https://github.com/facebook/lexical.git
synced 2025-05-20 16:48:04 +08:00
[Breaking Change][lexical-markdown] Bug Fix: Preserve paragraph separation after block elements (#7386)
This commit is contained in:
@ -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;
|
||||||
|
|
||||||
|
@ -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,
|
||||||
},
|
},
|
||||||
|
Reference in New Issue
Block a user