From ac07cea06efa041957d1ac227dd6e9ff2190b613 Mon Sep 17 00:00:00 2001 From: Antonella Sgarlatta Date: Thu, 5 Mar 2026 23:47:35 -0300 Subject: [PATCH] fix: Renders single line breaks properly on Super editor Show markdown (#2988) --- .../Lexical/Utils/MarkdownExport.ts | 25 ++++--------------- 1 file changed, 5 insertions(+), 20 deletions(-) diff --git a/packages/web/src/javascripts/Components/SuperEditor/Lexical/Utils/MarkdownExport.ts b/packages/web/src/javascripts/Components/SuperEditor/Lexical/Utils/MarkdownExport.ts index 53d45ff81..b8b4858ca 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Lexical/Utils/MarkdownExport.ts +++ b/packages/web/src/javascripts/Components/SuperEditor/Lexical/Utils/MarkdownExport.ts @@ -30,18 +30,14 @@ import { Transformer, } from '@lexical/markdown' -import { isEmptyParagraph, TRANSFORMERS, transformersByType } from './MarkdownImportExportUtils' +import { TRANSFORMERS, transformersByType } from './MarkdownImportExportUtils' /** * Renders string from markdown. The selection is moved to the start after the operation. */ -function createMarkdownExport( - transformers: Array, - shouldPreserveNewLines: boolean = false, -): (node?: ElementNode) => string { +function createMarkdownExport(transformers: Array): (node?: ElementNode) => string { const byType = transformersByType(transformers) const elementTransformers = [...byType.multilineElement, ...byType.element] - const isNewlineDelimited = !shouldPreserveNewLines // Export only uses text formats that are responsible for single format // e.g. it will filter out *** (bold, italic) and instead use separate ** and * @@ -56,16 +52,9 @@ function createMarkdownExport( const result = exportTopLevelElements(child, elementTransformers, textFormatTransformers, byType.textMatch) if (result != null) { - output.push( - // separate consecutive group of texts with a line break: eg. ["hello", "world"] -> ["hello", "/nworld"] - isNewlineDelimited && i > 0 && !isEmptyParagraph(child) && !isEmptyParagraph(children[i - 1]) - ? '\n'.concat(result) - : result, - ) + output.push(result) } } - // Ensure consecutive groups of texts are at least \n\n apart while each empty paragraph render as a newline. - // Eg. ["hello", "", "", "hi", "\nworld"] -> "hello\n\n\nhi\n\nworld" return output.join('\n') } } @@ -277,11 +266,7 @@ function hasFormat(node: LexicalNode | null | undefined, format: TextFormatType) return $isTextNode(node) && node.hasFormat(format) } -export function $convertToMarkdownString( - transformers: Array = TRANSFORMERS, - node?: ElementNode, - shouldPreserveNewLines: boolean = false, -): string { - const exportMarkdown = createMarkdownExport(transformers, shouldPreserveNewLines) +export function $convertToMarkdownString(transformers: Array = TRANSFORMERS, node?: ElementNode): string { + const exportMarkdown = createMarkdownExport(transformers) return exportMarkdown(node) }