fix: Fixed issue where empty new line in Super would create extra new lines when converting to Markdown

This commit is contained in:
Aman Harwara
2023-05-22 19:28:19 +05:30
parent 7a24b205a7
commit 799945b167
6 changed files with 34 additions and 25 deletions

View File

@@ -1,13 +1,13 @@
import { createHeadlessEditor } from '@lexical/headless'
import { $convertToMarkdownString } from '@lexical/markdown'
import { SuperConverterServiceInterface } from '@standardnotes/snjs'
import { LexicalEditor } from 'lexical'
import { $nodesOfType, LexicalEditor, ParagraphNode } from 'lexical'
import BlocksEditorTheme from '../Lexical/Theme/Theme'
import { BlockEditorNodes } from '../Lexical/Nodes/AllNodes'
import { MarkdownTransformers } from '../MarkdownTransformers'
import { $generateHtmlFromNodes } from '@lexical/html'
export class InvisibleSuperConverter implements SuperConverterServiceInterface {
export class HeadlessSuperConverter implements SuperConverterServiceInterface {
private editor: LexicalEditor
constructor() {
@@ -33,9 +33,16 @@ export class InvisibleSuperConverter implements SuperConverterServiceInterface {
() => {
switch (format) {
case 'txt':
case 'md':
case 'md': {
const paragraphs = $nodesOfType(ParagraphNode)
for (const paragraph of paragraphs) {
if (paragraph.isEmpty()) {
paragraph.remove()
}
}
content = $convertToMarkdownString(MarkdownTransformers)
break
}
case 'html':
content = $generateHtmlFromNodes(this.editor)
break