diff --git a/packages/block-library/src/heading/deprecated.js b/packages/block-library/src/heading/deprecated.js
new file mode 100644
index 00000000000000..4a3a7d2f6d3653
--- /dev/null
+++ b/packages/block-library/src/heading/deprecated.js
@@ -0,0 +1,79 @@
+/**
+ * External dependencies
+ */
+import classnames from 'classnames';
+
+/**
+ * WordPress dependencies
+ */
+import {
+ getColorClassName,
+ RichText,
+} from '@wordpress/block-editor';
+
+const blockSupports = {
+ className: false,
+ anchor: true,
+};
+
+const blockAttributes = {
+ align: {
+ type: 'string',
+ },
+ content: {
+ type: 'string',
+ source: 'html',
+ selector: 'h1,h2,h3,h4,h5,h6',
+ default: '',
+ },
+ level: {
+ type: 'number',
+ default: 2,
+ },
+ placeholder: {
+ type: 'string',
+ },
+ textColor: {
+ type: 'string',
+ },
+ customTextColor: {
+ type: 'string',
+ },
+};
+
+const deprecated = [
+ {
+ supports: blockSupports,
+ attributes: blockAttributes,
+ save( { attributes } ) {
+ const {
+ align,
+ level,
+ content,
+ textColor,
+ customTextColor,
+ } = attributes;
+ const tagName = 'h' + level;
+
+ const textClass = getColorClassName( 'color', textColor );
+
+ const className = classnames( {
+ [ textClass ]: textClass,
+ } );
+
+ return (
+
+ );
+ },
+ },
+];
+
+export default deprecated;
diff --git a/packages/block-library/src/heading/edit.js b/packages/block-library/src/heading/edit.js
index e8a396a147df57..7fc4721c9169ab 100644
--- a/packages/block-library/src/heading/edit.js
+++ b/packages/block-library/src/heading/edit.js
@@ -100,13 +100,13 @@ function HeadingEdit( {
onReplace={ onReplace }
onRemove={ () => onReplace( [] ) }
className={ classnames( className, {
+ [ `has-text-align-${ align }` ]: align,
'has-text-color': textColor.color,
[ textColor.class ]: textColor.class,
} ) }
placeholder={ placeholder || __( 'Write heading…' ) }
style={ {
color: textColor.color,
- textAlign: align,
} }
/>
>
diff --git a/packages/block-library/src/heading/index.js b/packages/block-library/src/heading/index.js
index 7706f44bb54ce6..1dc024193e4a76 100644
--- a/packages/block-library/src/heading/index.js
+++ b/packages/block-library/src/heading/index.js
@@ -6,6 +6,7 @@ import { __ } from '@wordpress/i18n';
/**
* Internal dependencies
*/
+import deprecated from './deprecated';
import edit from './edit';
import metadata from './block.json';
import save from './save';
@@ -25,6 +26,7 @@ export const settings = {
anchor: true,
},
transforms,
+ deprecated,
merge( attributes, attributesToMerge ) {
return {
content: ( attributes.content || '' ) + ( attributesToMerge.content || '' ),
diff --git a/packages/block-library/src/heading/save.js b/packages/block-library/src/heading/save.js
index f554ff815a121a..7cf0de59884828 100644
--- a/packages/block-library/src/heading/save.js
+++ b/packages/block-library/src/heading/save.js
@@ -14,10 +14,10 @@ import {
export default function save( { attributes } ) {
const {
align,
- level,
content,
- textColor,
customTextColor,
+ level,
+ textColor,
} = attributes;
const tagName = 'h' + level;
@@ -25,6 +25,7 @@ export default function save( { attributes } ) {
const className = classnames( {
[ textClass ]: textClass,
+ [ `has-text-align-${ align }` ]: align,
} );
return (
@@ -32,7 +33,6 @@ export default function save( { attributes } ) {
className={ className ? className : undefined }
tagName={ tagName }
style={ {
- textAlign: align,
color: textClass ? undefined : customTextColor,
} }
value={ content }
diff --git a/packages/block-library/src/style.scss b/packages/block-library/src/style.scss
index d33dd3c393c3b1..f9a2909ff360a8 100644
--- a/packages/block-library/src/style.scss
+++ b/packages/block-library/src/style.scss
@@ -147,6 +147,18 @@
font-size: 42px;
}
+// Text alignments.
+.has-text-align-center {
+ text-align: center;
+}
+
+.has-text-align-left {
+ text-align: left;
+}
+
+.has-text-align-right {
+ text-align: right;
+}
/**
* Vanilla Block Styles
diff --git a/packages/e2e-tests/fixtures/block-transforms.js b/packages/e2e-tests/fixtures/block-transforms.js
index 913953d69d2b3e..723552c024b545 100644
--- a/packages/e2e-tests/fixtures/block-transforms.js
+++ b/packages/e2e-tests/fixtures/block-transforms.js
@@ -168,7 +168,7 @@ export const EXPECTED_TRANSFORMS = {
originalBlock: 'Group',
availableTransforms: [],
},
- 'core__heading__h2-em': {
+ 'core__heading__h4-em': {
originalBlock: 'Heading',
availableTransforms: [
'Quote',
diff --git a/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.html b/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.html
new file mode 100644
index 00000000000000..b0fc3807468356
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.html
@@ -0,0 +1,3 @@
+
+
A picture is worth a thousand words, or so the saying goes
+
diff --git a/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.json b/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.json
new file mode 100644
index 00000000000000..0553075b8e24d6
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.json
@@ -0,0 +1,14 @@
+[
+ {
+ "clientId": "_clientId_0",
+ "name": "core/heading",
+ "isValid": true,
+ "attributes": {
+ "align": "right",
+ "content": "A picture is worth a thousand words, or so the saying goes",
+ "level": 3
+ },
+ "innerBlocks": [],
+ "originalContent": "A picture is worth a thousand words, or so the saying goes
"
+ }
+]
diff --git a/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.parsed.json b/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.parsed.json
new file mode 100644
index 00000000000000..abb13458d09aa7
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.parsed.json
@@ -0,0 +1,23 @@
+[
+ {
+ "blockName": "core/heading",
+ "attrs": {
+ "align": "right",
+ "level": 3
+ },
+ "innerBlocks": [],
+ "innerHTML": "\nA picture is worth a thousand words, or so the saying goes
\n",
+ "innerContent": [
+ "\nA picture is worth a thousand words, or so the saying goes
\n"
+ ]
+ },
+ {
+ "blockName": null,
+ "attrs": {},
+ "innerBlocks": [],
+ "innerHTML": "\n",
+ "innerContent": [
+ "\n"
+ ]
+ }
+]
diff --git a/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.serialized.html b/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.serialized.html
new file mode 100644
index 00000000000000..140a1929ad38c8
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__heading__deprecated-1.serialized.html
@@ -0,0 +1,3 @@
+
+A picture is worth a thousand words, or so the saying goes
+
diff --git a/packages/e2e-tests/fixtures/blocks/core__heading__h2-em.html b/packages/e2e-tests/fixtures/blocks/core__heading__h2-em.html
deleted file mode 100644
index 7755d1dcf4eae2..00000000000000
--- a/packages/e2e-tests/fixtures/blocks/core__heading__h2-em.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
-The Inserter Tool
-
diff --git a/packages/e2e-tests/fixtures/blocks/core__heading__h2-em.serialized.html b/packages/e2e-tests/fixtures/blocks/core__heading__h2-em.serialized.html
deleted file mode 100644
index 55ce73502b6185..00000000000000
--- a/packages/e2e-tests/fixtures/blocks/core__heading__h2-em.serialized.html
+++ /dev/null
@@ -1,3 +0,0 @@
-
-The Inserter Tool
-
diff --git a/packages/e2e-tests/fixtures/blocks/core__heading__h4-em.html b/packages/e2e-tests/fixtures/blocks/core__heading__h4-em.html
new file mode 100644
index 00000000000000..bd13c30bb968d1
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__heading__h4-em.html
@@ -0,0 +1,3 @@
+
+The Inserter Tool
+
diff --git a/packages/e2e-tests/fixtures/blocks/core__heading__h2-em.json b/packages/e2e-tests/fixtures/blocks/core__heading__h4-em.json
similarity index 72%
rename from packages/e2e-tests/fixtures/blocks/core__heading__h2-em.json
rename to packages/e2e-tests/fixtures/blocks/core__heading__h4-em.json
index b72785dd6d8c2a..32985e4bb53c85 100644
--- a/packages/e2e-tests/fixtures/blocks/core__heading__h2-em.json
+++ b/packages/e2e-tests/fixtures/blocks/core__heading__h4-em.json
@@ -5,9 +5,9 @@
"isValid": true,
"attributes": {
"content": "The Inserter Tool",
- "level": 2
+ "level": 4
},
"innerBlocks": [],
- "originalContent": "The Inserter Tool
"
+ "originalContent": "The Inserter Tool
"
}
]
diff --git a/packages/e2e-tests/fixtures/blocks/core__heading__h2-em.parsed.json b/packages/e2e-tests/fixtures/blocks/core__heading__h4-em.parsed.json
similarity index 62%
rename from packages/e2e-tests/fixtures/blocks/core__heading__h2-em.parsed.json
rename to packages/e2e-tests/fixtures/blocks/core__heading__h4-em.parsed.json
index e10209f2270c98..302248c57f6311 100644
--- a/packages/e2e-tests/fixtures/blocks/core__heading__h2-em.parsed.json
+++ b/packages/e2e-tests/fixtures/blocks/core__heading__h4-em.parsed.json
@@ -1,11 +1,13 @@
[
{
"blockName": "core/heading",
- "attrs": {},
+ "attrs": {
+ "level": 4
+ },
"innerBlocks": [],
- "innerHTML": "\nThe Inserter Tool
\n",
+ "innerHTML": "\nThe Inserter Tool
\n",
"innerContent": [
- "\nThe Inserter Tool
\n"
+ "\nThe Inserter Tool
\n"
]
},
{
diff --git a/packages/e2e-tests/fixtures/blocks/core__heading__h4-em.serialized.html b/packages/e2e-tests/fixtures/blocks/core__heading__h4-em.serialized.html
new file mode 100644
index 00000000000000..051e1c9f39b273
--- /dev/null
+++ b/packages/e2e-tests/fixtures/blocks/core__heading__h4-em.serialized.html
@@ -0,0 +1,3 @@
+
+The Inserter Tool
+
diff --git a/packages/e2e-tests/specs/__snapshots__/block-transforms.test.js.snap b/packages/e2e-tests/specs/__snapshots__/block-transforms.test.js.snap
index 25e50d75416a43..678dc348b496fd 100644
--- a/packages/e2e-tests/specs/__snapshots__/block-transforms.test.js.snap
+++ b/packages/e2e-tests/specs/__snapshots__/block-transforms.test.js.snap
@@ -64,13 +64,13 @@ exports[`Block transforms correctly transform block Heading in fixture core__hea
"
`;
-exports[`Block transforms correctly transform block Heading in fixture core__heading__h2-em into the Paragraph block 1`] = `
+exports[`Block transforms correctly transform block Heading in fixture core__heading__h4-em into the Paragraph block 1`] = `
"
The Inserter Tool
"
`;
-exports[`Block transforms correctly transform block Heading in fixture core__heading__h2-em into the Quote block 1`] = `
+exports[`Block transforms correctly transform block Heading in fixture core__heading__h4-em into the Quote block 1`] = `
"
The Inserter Tool
"