diff --git a/src/__test__/unit/convertor.spec.ts b/src/__test__/unit/convertor.spec.ts index 6b98f6e0a7..2ed8cdd3ef 100644 --- a/src/__test__/unit/convertor.spec.ts +++ b/src/__test__/unit/convertor.spec.ts @@ -1099,6 +1099,36 @@ describe('Convertor', () => { expect(result).toBe(`"test"a`); }); + it('should convert empty line between lists of wysiwig to
', () => { + const wwNodeJson = { + type: 'doc', + content: [ + { + type: 'bulletList', + content: [ + { + type: 'listItem', + content: [ + { type: 'paragraph', content: [{ type: 'text', text: 'test_1' }] }, + { type: 'paragraph', content: [] }, + ], + }, + { + type: 'listItem', + content: [{ type: 'paragraph', content: [{ type: 'text', text: 'test_2' }] }], + }, + ], + }, + ], + }; + + const wwNode = Node.fromJSON(schema, wwNodeJson); + + const result = convertor.toMarkdownText(wwNode); + + expect(result).toBe(`* test\\_1\n
\n* test\\_2`); + }); + it('should escape the backslash, which is a plain chracter in the middle of a sentence', () => { const markdown = source` backslash \\in the middle of a sentence diff --git a/src/convertors/toMarkdown/toMdConvertorState.ts b/src/convertors/toMarkdown/toMdConvertorState.ts index 99991a348f..b402f79753 100644 --- a/src/convertors/toMarkdown/toMdConvertorState.ts +++ b/src/convertors/toMarkdown/toMdConvertorState.ts @@ -78,6 +78,14 @@ export default class ToMdConvertorState { return ''; } + setDelim(delim: string) { + this.delim = delim; + } + + getDelim() { + return this.delim; + } + flushClose(size?: number) { if (!this.stopNewline && this.closed) { if (!this.isInBlank()) { @@ -106,12 +114,12 @@ export default class ToMdConvertorState { } wrapBlock(delim: string, firstDelim: string | null, node: Node, fn: () => void) { - const old = this.delim; + const old = this.getDelim(); this.write(firstDelim || delim); - this.delim += delim; + this.setDelim(this.getDelim() + delim); fn(); - this.delim = old; + this.setDelim(old); this.closeBlock(node); } diff --git a/src/convertors/toMarkdown/toMdNodeTypeWriters.ts b/src/convertors/toMarkdown/toMdNodeTypeWriters.ts index 3c4aeb0454..2cf7e16e0f 100644 --- a/src/convertors/toMarkdown/toMdNodeTypeWriters.ts +++ b/src/convertors/toMarkdown/toMdNodeTypeWriters.ts @@ -83,6 +83,14 @@ export const nodeTypeWriters: ToMdNodeTypeWriterMap = { if (emptyNode && prevEmptyNode) { state.write('
\n'); } else if (emptyNode && !prevEmptyNode && !firstChildNode) { + if (parent?.type.name === 'listItem') { + const prevDelim = state.getDelim(); + + state.setDelim(''); + state.write('
'); + + state.setDelim(prevDelim); + } state.write('\n'); } else { state.convertInline(node); diff --git a/types/convertor.d.ts b/types/convertor.d.ts index d44db7d00d..a3cb6bac3e 100644 --- a/types/convertor.d.ts +++ b/types/convertor.d.ts @@ -45,6 +45,8 @@ export type FirstDelimFn = (index: number) => string; export interface ToMdConvertorState { stopNewline: boolean; inTable: boolean; + getDelim(): string; + setDelim(delim: string): void; flushClose(size?: number): void; wrapBlock(delim: string, firstDelim: string | null, node: ProsemirrorNode, fn: () => void): void; ensureNewLine(): void;