diff --git a/packages/block-library/src/separator/transforms.js b/packages/block-library/src/separator/transforms.js index 54b4e983d92c3b..aedbeefc83ad8c 100644 --- a/packages/block-library/src/separator/transforms.js +++ b/packages/block-library/src/separator/transforms.js @@ -1,17 +1,33 @@ /** * WordPress dependencies */ -import { createBlock, getDefaultBlockName } from '@wordpress/blocks'; +import { + createBlock, + getBlockVariations, + getDefaultBlockName, +} from '@wordpress/blocks'; const transforms = { from: [ { type: 'input', regExp: /^-{3,}$/, - transform: () => [ - createBlock( 'core/separator' ), - createBlock( getDefaultBlockName() ), - ], + transform: () => { + // Check for default variation to preserve attributes. + const defaultVariation = getBlockVariations( + 'core/separator' + )?.find( ( variation ) => variation.isDefault ); + + // Fall back to empty attributes if no default variation is found. + const attributes = defaultVariation + ? defaultVariation.attributes + : {}; + + return [ + createBlock( 'core/separator', attributes ), + createBlock( getDefaultBlockName() ), + ]; + }, }, { type: 'raw',