Example #1
0
				transform: ( node ) => {
					// Search both figure and image classes. Alignment could be
					// set on either. ID is set on the image.
					const className = node.className + ' ' + node.querySelector( 'img' ).className;
					const alignMatches = /(?:^|\s)align(left|center|right)(?:$|\s)/.exec( className );
					const align = alignMatches ? alignMatches[ 1 ] : undefined;
					const idMatches = /(?:^|\s)wp-image-(\d+)(?:$|\s)/.exec( className );
					const id = idMatches ? Number( idMatches[ 1 ] ) : undefined;
					const anchorElement = node.querySelector( 'a' );
					const linkDestination = anchorElement && anchorElement.href ? 'custom' : undefined;
					const href = anchorElement && anchorElement.href ? anchorElement.href : undefined;
					const rel = anchorElement && anchorElement.rel ? anchorElement.rel : undefined;
					const linkClass = anchorElement && anchorElement.className ? anchorElement.className : undefined;
					const attributes = getBlockAttributes( 'core/image', node.outerHTML, { align, id, linkDestination, href, rel, linkClass } );
					return createBlock( 'core/image', attributes );
				},
Example #2
0
	onBlur() {
		const blockType = getBlockType( this.props.block.name );
		const attributes = getBlockAttributes( blockType, this.state.html, this.props.block.attributes );
		const isValid = isValidBlock( this.state.html, blockType, attributes );
		this.props.onChange( this.props.uid, attributes, this.state.html, isValid );
	}
Example #3
0
			},
			{
				type: 'raw',
				selector: 'h1,h2,h3,h4,h5,h6',
				schema: {
					h1: { children: getPhrasingContentSchema() },
					h2: { children: getPhrasingContentSchema() },
					h3: { children: getPhrasingContentSchema() },
					h4: { children: getPhrasingContentSchema() },
					h5: { children: getPhrasingContentSchema() },
					h6: { children: getPhrasingContentSchema() },
				},
				transform( node ) {
					return createBlock( 'core/heading', {
						...getBlockAttributes(
							'core/heading',
							node.outerHTML
						),
						level: getLevelFromHeadingNodeName( node.nodeName ),
					} );
				},
			},
			...[ 2, 3, 4, 5, 6 ].map( ( level ) => ( {
				type: 'prefix',
				prefix: Array( level + 1 ).join( '#' ),
				transform( content ) {
					return createBlock( 'core/heading', {
						level,
						content,
					} );
				},
			} ) ),