diff --git a/packages/block-editor/src/components/rich-text/index.js b/packages/block-editor/src/components/rich-text/index.js index 1cf2c6225afaa0..adbbdeeee7098d 100644 --- a/packages/block-editor/src/components/rich-text/index.js +++ b/packages/block-editor/src/components/rich-text/index.js @@ -2,7 +2,7 @@ * External dependencies */ import classnames from 'classnames'; -import { omit } from 'lodash'; +import { castArray, omit } from 'lodash'; /** * WordPress dependencies @@ -64,9 +64,10 @@ class RichTextWrapper extends Component { } ); if ( transformation ) { - onReplace( [ + onReplace( castArray( transformation.transform( { content: value.text } ), - ] ); + ) ); + return; } } diff --git a/packages/block-library/src/verse/edit.js b/packages/block-library/src/verse/edit.js index ff0beac6622fc1..08d4d83dea4c46 100644 --- a/packages/block-library/src/verse/edit.js +++ b/packages/block-library/src/verse/edit.js @@ -13,7 +13,7 @@ import { AlignmentToolbar, } from '@wordpress/block-editor'; -export default function VerseEdit( { attributes, setAttributes, className, mergeBlocks } ) { +export default function VerseEdit( { attributes, setAttributes, className, mergeBlocks, onReplace } ) { const { textAlign, content } = attributes; return ( @@ -40,6 +40,7 @@ export default function VerseEdit( { attributes, setAttributes, className, merge [ `has-text-align-${ textAlign }` ]: textAlign, } ) } onMerge={ mergeBlocks } + onReplace={ onReplace } /> ); diff --git a/packages/block-library/src/verse/tranforms.js b/packages/block-library/src/verse/tranforms.js index 240b1ac023e1d9..d4d4de9762b334 100644 --- a/packages/block-library/src/verse/tranforms.js +++ b/packages/block-library/src/verse/tranforms.js @@ -5,6 +5,16 @@ import { createBlock } from '@wordpress/blocks'; const transforms = { from: [ + { + type: 'enter', + regExp: /\n$/, + transform: ( { content } ) => [ + createBlock( 'core/verse', { + content: content.replace( /\n$/, '' ), + } ), + createBlock( 'core/paragraph' ), + ], + }, { type: 'block', blocks: [ 'core/paragraph' ],