File tree Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Expand file tree Collapse file tree 2 files changed +27
-1
lines changed Original file line number Diff line number Diff 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 ,
Original file line number Diff line number Diff 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
318335describe ( 'Trailing nodes' , ( ) => {
You can’t perform that action at this time.
0 commit comments