diff --git a/blocks/api/index.js b/blocks/api/index.js
index c4fd64bcf4c76d..7f0653a133c5b3 100644
--- a/blocks/api/index.js
+++ b/blocks/api/index.js
@@ -1,7 +1,12 @@
export { createBlock, getPossibleBlockTransformations, switchToBlockType, createReusableBlock } from './factory';
export { default as parse, getBlockAttributes } from './parser';
export { default as rawHandler } from './raw-handling';
-export { default as serialize, getBlockDefaultClassname, getBlockContent } from './serializer';
+export {
+ default as serialize,
+ getBlockContent,
+ getBlockDefaultClassname,
+ getSaveElement,
+} from './serializer';
export { isValidBlock } from './validation';
export { getCategories } from './categories';
export {
diff --git a/blocks/api/serializer.js b/blocks/api/serializer.js
index 91ebc6fc0c5f27..24b903997c3fc4 100644
--- a/blocks/api/serializer.js
+++ b/blocks/api/serializer.js
@@ -28,24 +28,25 @@ export function getBlockDefaultClassname( blockName ) {
/**
* Given a block type containg a save render implementation and attributes, returns the
- * static markup to be saved.
+ * enhanced element to be saved or string when raw HTML expected.
*
* @param {Object} blockType Block type
* @param {Object} attributes Block attributes
- * @return {string} Save content
+ * @return {Object|string} Save content
*/
-export function getSaveContent( blockType, attributes ) {
+export function getSaveElement( blockType, attributes ) {
const { save } = blockType;
- let saveContent;
+
+ let saveElement;
if ( save.prototype instanceof Component ) {
- saveContent = createElement( save, { attributes } );
+ saveElement = createElement( save, { attributes } );
} else {
- saveContent = save( { attributes } );
+ saveElement = save( { attributes } );
// Special-case function render implementation to allow raw HTML return
- if ( 'string' === typeof saveContent ) {
- return saveContent;
+ if ( 'string' === typeof saveElement ) {
+ return saveElement;
}
}
@@ -59,10 +60,28 @@ export function getSaveContent( blockType, attributes ) {
return cloneElement( element, props );
};
- const contentWithExtraProps = Children.map( saveContent, addExtraContainerProps );
+
+ return Children.map( saveElement, addExtraContainerProps );
+}
+
+/**
+ * Given a block type containg a save render implementation and attributes, returns the
+ * static markup to be saved.
+ *
+ * @param {Object} blockType Block type
+ * @param {Object} attributes Block attributes
+ * @return {string} Save content
+ */
+export function getSaveContent( blockType, attributes ) {
+ const saveElement = getSaveElement( blockType, attributes );
+
+ // Special-case function render implementation to allow raw HTML return
+ if ( 'string' === typeof saveElement ) {
+ return saveElement;
+ }
// Otherwise, infer as element
- return renderToString( contentWithExtraProps );
+ return renderToString( saveElement );
}
/**
diff --git a/blocks/block-edit/index.js b/blocks/block-edit/index.js
index 87d89199fa014f..8d2c93d9f24d53 100644
--- a/blocks/block-edit/index.js
+++ b/blocks/block-edit/index.js
@@ -1,3 +1,8 @@
+/**
+ * External dependencies
+ */
+import classnames from 'classnames';
+
/**
* WordPress dependencies
*/
@@ -6,22 +11,32 @@ import { withFilters } from '@wordpress/components';
/**
* Internal dependencies
*/
-import { getBlockType } from '../api';
+import {
+ getBlockType,
+ getBlockDefaultClassname,
+ hasBlockSupport,
+} from '../api';
export function BlockEdit( props ) {
- const { name, ...editProps } = props;
+ const { name, attributes = {} } = props;
const blockType = getBlockType( name );
if ( ! blockType ) {
return null;
}
+ // Generate a class name for the block's editable form
+ const generatedClassName = hasBlockSupport( blockType, 'className', true ) ?
+ getBlockDefaultClassname( name ) :
+ null;
+ const className = classnames( generatedClassName, attributes.className );
+
// `edit` and `save` are functions or components describing the markup
// with which a block is displayed. If `blockType` is valid, assign
// them preferencially as the render value for the block.
const Edit = blockType.edit || blockType.save;
- return