Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/extensions/RichText.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
22 changes: 22 additions & 0 deletions src/tests/markdown.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,28 @@ describe('Markdown serializer from html', () => {
'<details>\n<summary>**summary**</summary>\n```\ncode\n```\n\n</details>\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')
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
expect(md).toBe(source + ' editing')
expect(md).toBe(source + ' editing')
tiptap.destroy()

We had several test failures due to dangling editor instances in the past, so better to always explicitly destroy the editor in tests.

}

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')
})
})

describe('Trailing nodes', () => {
Expand Down
Loading