Skip to content

Commit 29e9f52

Browse files
committed
Add transforms to/from core code block
This adds transforms so that SyntaxHighlighter code blocks can be directly converted from and to the Gutenberg `core/code` blocks. When pasting a markdown post into Gutenberg, code blocks in the post are automatically converted to `core/code` blocks, so I have to manually change them into SyntaxHighlighter blocks instead. Without this patch, that means creating a new block, copy/pasting the content of the old block to the new one, and then deleting the old block. For a long post this takes quite a lot of time. With this change it will be a two-click operation per block.
1 parent a75f027 commit 29e9f52

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

src/blocks.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,22 @@ registerBlockType( 'syntaxhighlighter/code', {
101101
},
102102
},
103103
},
104+
{
105+
type: 'block',
106+
blocks: [ 'core/code' ],
107+
transform: ( { content } ) => {
108+
return createBlock( 'syntaxhighlighter/code', { content } );
109+
},
110+
},
111+
],
112+
to: [
113+
{
114+
type: 'block',
115+
blocks: [ 'core/code' ],
116+
transform: ( { content } ) => {
117+
return createBlock( 'core/code', { content } );
118+
},
119+
},
104120
],
105121
},
106122

0 commit comments

Comments
 (0)