From 80551ee7543f30780989623c18580e763da94af9 Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Fri, 13 Jun 2025 12:58:48 +0200 Subject: [PATCH 1/2] fix: Do not escape possible other editors syntax when serializing Signed-off-by: Julius Knorr --- src/extensions/RichText.js | 11 ++++++++++- src/tests/markdown.spec.js | 17 +++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/extensions/RichText.js b/src/extensions/RichText.js index 65d98391432..3b11e059055 100644 --- a/src/extensions/RichText.js +++ b/src/extensions/RichText.js @@ -67,7 +67,16 @@ export default Extension.create({ const defaultExtensions = [ this.options.editing ? Markdown : null, Document, - Text, + Text.extend({ + toMarkdown(state, node) { + const originalEsc = state.esc + state.esc = (text) => { + text = originalEsc.bind(state)(text) + return text.replace(/\\\[/g, '[').replace(/\\\]/g, ']') + } + state.text(node.textContent) + }, + }), Paragraph, HardBreak, Heading, diff --git a/src/tests/markdown.spec.js b/src/tests/markdown.spec.js index cc1686f5c7f..923b679cf1a 100644 --- a/src/tests/markdown.spec.js +++ b/src/tests/markdown.spec.js @@ -313,6 +313,23 @@ describe('Markdown serializer from html', () => { '
\n**summary**\n```\ncode\n```\n\n
\n', ) }) + + const assertKeepSyntax = (source) => { + const tiptap = createRichEditor() + tiptap.commands.setContent(markdownit.render(source)) + + const end = tiptap.state.doc.content.size - 1 + tiptap.commands.insertContentAt(end, ' editing') + + const serializer = createMarkdownSerializer(tiptap.schema) + const md = serializer.serialize(tiptap.state.doc) + expect(md).toBe(source + ' editing') + } + + test('keep syntax for brackets', () => { + assertKeepSyntax('test [[foo]] bar') + assertKeepSyntax('test ![[foo]] bar') + }) }) describe('Trailing nodes', () => { From 7ef7b0033275416864082a6821ed17053ae58f9e Mon Sep 17 00:00:00 2001 From: Julius Knorr Date: Wed, 18 Jun 2025 08:20:31 +0200 Subject: [PATCH 2/2] fixup! fix: Do not escape possible other editors syntax when serializing --- src/tests/markdown.spec.js | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/tests/markdown.spec.js b/src/tests/markdown.spec.js index 923b679cf1a..063586357a2 100644 --- a/src/tests/markdown.spec.js +++ b/src/tests/markdown.spec.js @@ -329,6 +329,11 @@ describe('Markdown serializer from html', () => { test('keep syntax for brackets', () => { assertKeepSyntax('test [[foo]] bar') assertKeepSyntax('test ![[foo]] bar') + assertKeepSyntax('test ![[note#^block]] bar') + assertKeepSyntax('test [mytest] foo') + assertKeepSyntax('test [[mytest]] [abc](test) foo') + assertKeepSyntax('test #foo test') + assertKeepSyntax('\\\\[ test') }) })