Skip to content

Commit 642e6e8

Browse files
committed
fix: Do not escape possible other editors syntax when serializing
Signed-off-by: Julius Knorr <[email protected]>
1 parent 8d8d779 commit 642e6e8

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/extensions/RichText.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ export default Extension.create({
6767
const defaultExtensions = [
6868
this.options.editing ? Markdown : null,
6969
Document,
70-
Text,
70+
Text.extend({
71+
toMarkdown(state, node) {
72+
const originalEsc = state.esc
73+
state.esc = (text) => {
74+
text = originalEsc.bind(state)(text)
75+
return text.replace(/\\\[/g, '[').replace(/\\\]/g, ']')
76+
}
77+
state.text(node.textContent)
78+
},
79+
}),
7180
Paragraph,
7281
HardBreak,
7382
Heading,

src/tests/markdown.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,23 @@ describe('Markdown serializer from html', () => {
313313
'<details>\n<summary>**summary**</summary>\n```\ncode\n```\n\n</details>\n',
314314
)
315315
})
316+
317+
const assertKeepSyntax = (source) => {
318+
const tiptap = createRichEditor()
319+
tiptap.commands.setContent(markdownit.render(source))
320+
321+
const end = tiptap.state.doc.content.size - 1
322+
tiptap.commands.insertContentAt(end, " editing");
323+
324+
const serializer = createMarkdownSerializer(tiptap.schema)
325+
const md = serializer.serialize(tiptap.state.doc)
326+
expect(md).toBe(source + ' editing')
327+
}
328+
329+
test('keep syntax for brackets', () => {
330+
assertKeepSyntax('test [[foo]] bar')
331+
assertKeepSyntax('test ![[foo]] bar')
332+
})
316333
})
317334

318335
describe('Trailing nodes', () => {

0 commit comments

Comments
 (0)