import { createBlock } from '@wordpress/blocks'; import type { BlockType } from '@wordpress/blocks'; import type { MoreAttributes } from './types'; const transforms: BlockType< MoreAttributes >[ 'transforms' ] = { from: [ { type: 'raw', schema: { 'wp-block': { attributes: [ 'data-block' ] }, }, isMatch: ( node ) => ( node as HTMLElement ).dataset && ( node as HTMLElement ).dataset.block === 'core/more', transform( node ) { const { customText, noTeaser } = ( node as HTMLElement ) .dataset; const attrs: Partial< MoreAttributes > = {}; // Don't copy unless defined and not an empty string. if ( customText ) { attrs.customText = customText; } // Special handling for boolean. if ( noTeaser === '' ) { attrs.noTeaser = true; } return createBlock( 'core/more', attrs ); }, }, ], }; export default transforms;