diff --git a/plugins/docs/markdown-blocks.test.ts b/plugins/docs/markdown-blocks.test.ts index 8e53683d3..9f0f9ace4 100644 --- a/plugins/docs/markdown-blocks.test.ts +++ b/plugins/docs/markdown-blocks.test.ts @@ -87,6 +87,46 @@ function topLevelRange(editor: Editor, text: string) { } describe("markdown blocks", () => { + it.each([ + ["a lone tilde", "Estimate ~72 items.", "Edited Estimate ~72 items.\n"], + [ + "a plain URL", + "Visit https://serialize.test/guide", + "Edited Visit https://serialize.test/guide\n", + ], + ])("saves edited text without unnecessary syntax for %s", (_name, source, expected) => { + const { editor, save } = open(`${source}\n`); + try { + editor.commands.insertContentAt(1, "Edited "); + const saved = save(); + console.log(JSON.stringify({ case: _name, saved })); + expect(saved).toBe(expected); + } finally { + editor.destroy(); + } + }); + + it("saves consecutive intentional breaks without backslash-only lines", () => { + const { editor, save } = open("Alpha.\n"); + try { + editor.commands.setTextSelection(7); + editor.commands.setHardBreak(); + editor.commands.setHardBreak(); + editor.commands.insertContent("Omega."); + const saved = save(); + console.log(JSON.stringify({ case: "consecutive breaks", saved })); + expect(saved).not.toMatch(/^\\$/m); + const reopened = open(saved); + try { + expect(reopened.editor.getJSON()).toEqual(editor.getJSON()); + } finally { + reopened.editor.destroy(); + } + } finally { + editor.destroy(); + } + }); + it("saves an unedited document byte for byte", () => { const { editor, save } = open(DOCUMENT); try {