diff --git a/packages/block-library/src/pullquote/block.json b/packages/block-library/src/pullquote/block.json index 1fa9770636ac4e..e514c004576c05 100644 --- a/packages/block-library/src/pullquote/block.json +++ b/packages/block-library/src/pullquote/block.json @@ -10,8 +10,7 @@ "value": { "type": "string", "source": "html", - "selector": "blockquote", - "multiline": "p", + "selector": "p", "__experimentalRole": "content" }, "citation": { diff --git a/packages/block-library/src/pullquote/deprecated.js b/packages/block-library/src/pullquote/deprecated.js index ba55f16c241cc9..9a9c6030b8e22c 100644 --- a/packages/block-library/src/pullquote/deprecated.js +++ b/packages/block-library/src/pullquote/deprecated.js @@ -15,6 +15,12 @@ import { useBlockProps, } from '@wordpress/block-editor'; import { select } from '@wordpress/data'; +import { + create, + replace, + toHTMLString, + __UNSTABLE_LINE_SEPARATOR, +} from '@wordpress/rich-text'; /** * Internal dependencies @@ -58,458 +64,530 @@ function parseBorderColor( styleString ) { } } -// TODO: this is ripe for a bit of a clean up according to the example in https://developer.wordpress.org/block-editor/reference-guides/block-api/block-deprecation/#example -const deprecated = [ - { - attributes: { - ...blockAttributes, - }, - save( { attributes } ) { - const { - mainColor, - customMainColor, - customTextColor, - textColor, - value, - citation, - className, - } = attributes; - - const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); - - let figureClasses, figureStyles; - - // Is solid color style - if ( isSolidColorStyle ) { - const backgroundClass = getColorClassName( - 'background-color', - mainColor - ); - - figureClasses = classnames( { - 'has-background': backgroundClass || customMainColor, - [ backgroundClass ]: backgroundClass, - } ); - - figureStyles = { - backgroundColor: backgroundClass - ? undefined - : customMainColor, - }; - // Is normal style and a custom color is being used ( we can set a style directly with its value) - } else if ( customMainColor ) { - figureStyles = { - borderColor: customMainColor, - }; - } +function multilineToInline( value ) { + return toHTMLString( { + value: replace( + create( { html: value, multilineTag: 'p' } ), + new RegExp( __UNSTABLE_LINE_SEPARATOR, 'g' ), + '\n' + ), + } ); +} - const blockquoteTextColorClass = getColorClassName( - 'color', - textColor - ); - const blockquoteClasses = classnames( { - 'has-text-color': textColor || customTextColor, - [ blockquoteTextColorClass ]: blockquoteTextColorClass, - } ); +const v5 = { + attributes: { + value: { + type: 'string', + source: 'html', + selector: 'blockquote', + multiline: 'p', + __experimentalRole: 'content', + }, + citation: { + type: 'string', + source: 'html', + selector: 'cite', + default: '', + __experimentalRole: 'content', + }, + textAlign: { + type: 'string', + }, + }, + save( { attributes } ) { + const { textAlign, citation, value } = attributes; + const shouldShowCitation = ! RichText.isEmpty( citation ); + + return ( +
+
+ + { shouldShowCitation && ( + + ) } +
+
+ ); + }, + migrate( { value, ...attributes } ) { + return { + value: multilineToInline( value ), + ...attributes, + }; + }, +}; - const blockquoteStyles = blockquoteTextColorClass - ? undefined - : { color: customTextColor }; +// TODO: this is ripe for a bit of a clean up according to the example in https://developer.wordpress.org/block-editor/reference-guides/block-api/block-deprecation/#example - return ( -
-
- - { ! RichText.isEmpty( citation ) && ( - - ) } -
-
- ); - }, - migrate( { - className, +const v4 = { + attributes: { + ...blockAttributes, + }, + save( { attributes } ) { + const { mainColor, customMainColor, customTextColor, - ...attributes - } ) { - const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); - let style; - - if ( customMainColor ) { - if ( ! isSolidColorStyle ) { - // Block supports: Set style.border.color if a deprecated block has a default style and a `customMainColor` attribute. - style = { - border: { - color: customMainColor, - }, - }; - } else { - // Block supports: Set style.color.background if a deprecated block has a solid style and a `customMainColor` attribute. - style = { - color: { - background: customMainColor, - }, - }; - } - } + textColor, + value, + citation, + className, + } = attributes; - // Block supports: Set style.color.text if a deprecated block has a `customTextColor` attribute. - if ( customTextColor && style ) { - style.color = { - ...style.color, - text: customTextColor, - }; - } + const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); + + let figureClasses, figureStyles; - return { - className, - backgroundColor: isSolidColorStyle ? mainColor : undefined, - borderColor: isSolidColorStyle ? undefined : mainColor, - textAlign: isSolidColorStyle ? 'left' : undefined, - style, - ...attributes, + // Is solid color style + if ( isSolidColorStyle ) { + const backgroundClass = getColorClassName( + 'background-color', + mainColor + ); + + figureClasses = classnames( { + 'has-background': backgroundClass || customMainColor, + [ backgroundClass ]: backgroundClass, + } ); + + figureStyles = { + backgroundColor: backgroundClass ? undefined : customMainColor, }; - }, + // Is normal style and a custom color is being used ( we can set a style directly with its value) + } else if ( customMainColor ) { + figureStyles = { + borderColor: customMainColor, + }; + } + + const blockquoteTextColorClass = getColorClassName( + 'color', + textColor + ); + const blockquoteClasses = classnames( { + 'has-text-color': textColor || customTextColor, + [ blockquoteTextColorClass ]: blockquoteTextColorClass, + } ); + + const blockquoteStyles = blockquoteTextColorClass + ? undefined + : { color: customTextColor }; + + return ( +
+
+ + { ! RichText.isEmpty( citation ) && ( + + ) } +
+
+ ); }, - { - attributes: { - ...blockAttributes, - // figureStyle is an attribute that never existed. - // We are using it as a way to access the styles previously applied to the figure. - figureStyle: { - source: 'attribute', - selector: 'figure', - attribute: 'style', - }, - }, - save( { attributes } ) { - const { - mainColor, - customMainColor, - textColor, - customTextColor, - value, - citation, - className, - figureStyle, - } = attributes; - - const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); - - let figureClasses, figureStyles; - - // Is solid color style - if ( isSolidColorStyle ) { - const backgroundClass = getColorClassName( - 'background-color', - mainColor - ); - - figureClasses = classnames( { - 'has-background': backgroundClass || customMainColor, - [ backgroundClass ]: backgroundClass, - } ); - - figureStyles = { - backgroundColor: backgroundClass - ? undefined - : customMainColor, + migrate( { + value, + className, + mainColor, + customMainColor, + customTextColor, + ...attributes + } ) { + const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); + let style; + + if ( customMainColor ) { + if ( ! isSolidColorStyle ) { + // Block supports: Set style.border.color if a deprecated block has a default style and a `customMainColor` attribute. + style = { + border: { + color: customMainColor, + }, }; - // Is normal style and a custom color is being used ( we can set a style directly with its value) - } else if ( customMainColor ) { - figureStyles = { - borderColor: customMainColor, - }; - // If normal style and a named color are being used, we need to retrieve the color value to set the style, - // as there is no expectation that themes create classes that set border colors. - } else if ( mainColor ) { - // Previously here we queried the color settings to know the color value - // of a named color. This made the save function impure and the block was refactored, - // because meanwhile a change in the editor made it impossible to query color settings in the save function. - // Here instead of querying the color settings to know the color value, we retrieve the value - // directly from the style previously serialized. - const borderColor = parseBorderColor( figureStyle ); - figureStyles = { - borderColor, + } else { + // Block supports: Set style.color.background if a deprecated block has a solid style and a `customMainColor` attribute. + style = { + color: { + background: customMainColor, + }, }; } + } - const blockquoteTextColorClass = getColorClassName( - 'color', - textColor - ); - const blockquoteClasses = - ( textColor || customTextColor ) && - classnames( 'has-text-color', { - [ blockquoteTextColorClass ]: blockquoteTextColorClass, - } ); - - const blockquoteStyles = blockquoteTextColorClass - ? undefined - : { color: customTextColor }; - - return ( -
-
- - { ! RichText.isEmpty( citation ) && ( - - ) } -
-
- ); - }, - migrate( { + // Block supports: Set style.color.text if a deprecated block has a `customTextColor` attribute. + if ( customTextColor && style ) { + style.color = { + ...style.color, + text: customTextColor, + }; + } + + return { + value: multilineToInline( value ), className, - figureStyle, + backgroundColor: isSolidColorStyle ? mainColor : undefined, + borderColor: isSolidColorStyle ? undefined : mainColor, + textAlign: isSolidColorStyle ? 'left' : undefined, + style, + ...attributes, + }; + }, +}; + +const v3 = { + attributes: { + ...blockAttributes, + // figureStyle is an attribute that never existed. + // We are using it as a way to access the styles previously applied to the figure. + figureStyle: { + source: 'attribute', + selector: 'figure', + attribute: 'style', + }, + }, + save( { attributes } ) { + const { mainColor, customMainColor, + textColor, customTextColor, - ...attributes - } ) { - const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); - let style; - - if ( customMainColor ) { - if ( ! isSolidColorStyle ) { - // Block supports: Set style.border.color if a deprecated block has a default style and a `customMainColor` attribute. - style = { - border: { - color: customMainColor, - }, - }; - } else { - // Block supports: Set style.color.background if a deprecated block has a solid style and a `customMainColor` attribute. - style = { - color: { - background: customMainColor, - }, - }; - } - } + value, + citation, + className, + figureStyle, + } = attributes; - // Block supports: Set style.color.text if a deprecated block has a `customTextColor` attribute. - if ( customTextColor && style ) { - style.color = { - ...style.color, - text: customTextColor, - }; - } - // If is the default style, and a main color is set, - // migrate the main color value into a custom border color. - // The custom border color value is retrieved by parsing the figure styles. - if ( ! isSolidColorStyle && mainColor && figureStyle ) { - const borderColor = parseBorderColor( figureStyle ); - if ( borderColor ) { - return { - ...attributes, - className, - // Block supports: Set style.border.color if a deprecated block has `mainColor`, inline border CSS and is not a solid color style. - style: { - border: { - color: borderColor, - }, - }, - }; - } - } - return { - className, - backgroundColor: isSolidColorStyle ? mainColor : undefined, - borderColor: isSolidColorStyle ? undefined : mainColor, - textAlign: isSolidColorStyle ? 'left' : undefined, - style, - ...attributes, + const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); + + let figureClasses, figureStyles; + + // Is solid color style + if ( isSolidColorStyle ) { + const backgroundClass = getColorClassName( + 'background-color', + mainColor + ); + + figureClasses = classnames( { + 'has-background': backgroundClass || customMainColor, + [ backgroundClass ]: backgroundClass, + } ); + + figureStyles = { + backgroundColor: backgroundClass ? undefined : customMainColor, }; - }, + // Is normal style and a custom color is being used ( we can set a style directly with its value) + } else if ( customMainColor ) { + figureStyles = { + borderColor: customMainColor, + }; + // If normal style and a named color are being used, we need to retrieve the color value to set the style, + // as there is no expectation that themes create classes that set border colors. + } else if ( mainColor ) { + // Previously here we queried the color settings to know the color value + // of a named color. This made the save function impure and the block was refactored, + // because meanwhile a change in the editor made it impossible to query color settings in the save function. + // Here instead of querying the color settings to know the color value, we retrieve the value + // directly from the style previously serialized. + const borderColor = parseBorderColor( figureStyle ); + figureStyles = { + borderColor, + }; + } + + const blockquoteTextColorClass = getColorClassName( + 'color', + textColor + ); + const blockquoteClasses = + ( textColor || customTextColor ) && + classnames( 'has-text-color', { + [ blockquoteTextColorClass ]: blockquoteTextColorClass, + } ); + + const blockquoteStyles = blockquoteTextColorClass + ? undefined + : { color: customTextColor }; + + return ( +
+
+ + { ! RichText.isEmpty( citation ) && ( + + ) } +
+
+ ); }, - { - attributes: blockAttributes, - save( { attributes } ) { - const { - mainColor, - customMainColor, - textColor, - customTextColor, - value, - citation, - className, - } = attributes; - const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); - - let figureClass, figureStyles; - // Is solid color style - if ( isSolidColorStyle ) { - figureClass = getColorClassName( - 'background-color', - mainColor - ); - if ( ! figureClass ) { - figureStyles = { - backgroundColor: customMainColor, - }; - } - // Is normal style and a custom color is being used ( we can set a style directly with its value) - } else if ( customMainColor ) { - figureStyles = { - borderColor: customMainColor, + migrate( { + value, + className, + figureStyle, + mainColor, + customMainColor, + customTextColor, + ...attributes + } ) { + const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); + let style; + + if ( customMainColor ) { + if ( ! isSolidColorStyle ) { + // Block supports: Set style.border.color if a deprecated block has a default style and a `customMainColor` attribute. + style = { + border: { + color: customMainColor, + }, }; - // Is normal style and a named color is being used, we need to retrieve the color value to set the style, - // as there is no expectation that themes create classes that set border colors. - } else if ( mainColor ) { - const colors = get( - select( blockEditorStore ).getSettings(), - [ 'colors' ], - [] - ); - const colorObject = getColorObjectByAttributeValues( - colors, - mainColor - ); - figureStyles = { - borderColor: colorObject.color, + } else { + // Block supports: Set style.color.background if a deprecated block has a solid style and a `customMainColor` attribute. + style = { + color: { + background: customMainColor, + }, }; } + } - const blockquoteTextColorClass = getColorClassName( - 'color', - textColor - ); - const blockquoteClasses = - textColor || customTextColor - ? classnames( 'has-text-color', { - [ blockquoteTextColorClass ]: - blockquoteTextColorClass, - } ) - : undefined; - const blockquoteStyle = blockquoteTextColorClass - ? undefined - : { color: customTextColor }; - return ( -
-
- - { ! RichText.isEmpty( citation ) && ( - - ) } -
-
- ); - }, - migrate( { - className, - mainColor, - customMainColor, - customTextColor, - ...attributes - } ) { - const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); - let style = {}; - - if ( customMainColor ) { - if ( ! isSolidColorStyle ) { - // Block supports: Set style.border.color if a deprecated block has a default style and a `customMainColor` attribute. - style = { + // Block supports: Set style.color.text if a deprecated block has a `customTextColor` attribute. + if ( customTextColor && style ) { + style.color = { + ...style.color, + text: customTextColor, + }; + } + // If is the default style, and a main color is set, + // migrate the main color value into a custom border color. + // The custom border color value is retrieved by parsing the figure styles. + if ( ! isSolidColorStyle && mainColor && figureStyle ) { + const borderColor = parseBorderColor( figureStyle ); + if ( borderColor ) { + return { + value: multilineToInline( value ), + ...attributes, + className, + // Block supports: Set style.border.color if a deprecated block has `mainColor`, inline border CSS and is not a solid color style. + style: { border: { - color: customMainColor, + color: borderColor, }, - }; - } else { - // Block supports: Set style.color.background if a deprecated block has a solid style and a `customMainColor` attribute. - style = { - color: { - background: customMainColor, - }, - }; - } + }, + }; } + } + return { + value: multilineToInline( value ), + className, + backgroundColor: isSolidColorStyle ? mainColor : undefined, + borderColor: isSolidColorStyle ? undefined : mainColor, + textAlign: isSolidColorStyle ? 'left' : undefined, + style, + ...attributes, + }; + }, +}; - // Block supports: Set style.color.text if a deprecated block has a `customTextColor` attribute. - if ( customTextColor && style ) { - style.color = { - ...style.color, - text: customTextColor, +const v2 = { + attributes: blockAttributes, + save( { attributes } ) { + const { + mainColor, + customMainColor, + textColor, + customTextColor, + value, + citation, + className, + } = attributes; + const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); + + let figureClass, figureStyles; + // Is solid color style + if ( isSolidColorStyle ) { + figureClass = getColorClassName( 'background-color', mainColor ); + if ( ! figureClass ) { + figureStyles = { + backgroundColor: customMainColor, }; } - - return { - className, - backgroundColor: isSolidColorStyle ? mainColor : undefined, - borderColor: isSolidColorStyle ? undefined : mainColor, - textAlign: isSolidColorStyle ? 'left' : undefined, - style, - ...attributes, + // Is normal style and a custom color is being used ( we can set a style directly with its value) + } else if ( customMainColor ) { + figureStyles = { + borderColor: customMainColor, }; - }, - }, - { - attributes: { - ...blockAttributes, - }, - save( { attributes } ) { - const { value, citation } = attributes; - return ( -
+ // Is normal style and a named color is being used, we need to retrieve the color value to set the style, + // as there is no expectation that themes create classes that set border colors. + } else if ( mainColor ) { + const colors = get( + select( blockEditorStore ).getSettings(), + [ 'colors' ], + [] + ); + const colorObject = getColorObjectByAttributeValues( + colors, + mainColor + ); + figureStyles = { + borderColor: colorObject.color, + }; + } + + const blockquoteTextColorClass = getColorClassName( + 'color', + textColor + ); + const blockquoteClasses = + textColor || customTextColor + ? classnames( 'has-text-color', { + [ blockquoteTextColorClass ]: blockquoteTextColorClass, + } ) + : undefined; + const blockquoteStyle = blockquoteTextColorClass + ? undefined + : { color: customTextColor }; + return ( +
+
{ ! RichText.isEmpty( citation ) && ( ) }
- ); - }, +
+ ); }, - { - attributes: { - ...blockAttributes, - citation: { - type: 'string', - source: 'html', - selector: 'footer', - }, - align: { - type: 'string', - default: 'none', - }, - }, + migrate( { + value, + className, + mainColor, + customMainColor, + customTextColor, + ...attributes + } ) { + const isSolidColorStyle = includes( className, SOLID_COLOR_CLASS ); + let style = {}; + + if ( customMainColor ) { + if ( ! isSolidColorStyle ) { + // Block supports: Set style.border.color if a deprecated block has a default style and a `customMainColor` attribute. + style = { + border: { + color: customMainColor, + }, + }; + } else { + // Block supports: Set style.color.background if a deprecated block has a solid style and a `customMainColor` attribute. + style = { + color: { + background: customMainColor, + }, + }; + } + } - save( { attributes } ) { - const { value, citation, align } = attributes; + // Block supports: Set style.color.text if a deprecated block has a `customTextColor` attribute. + if ( customTextColor && style ) { + style.color = { + ...style.color, + text: customTextColor, + }; + } - return ( -
- - { ! RichText.isEmpty( citation ) && ( - - ) } -
- ); + return { + value: multilineToInline( value ), + className, + backgroundColor: isSolidColorStyle ? mainColor : undefined, + borderColor: isSolidColorStyle ? undefined : mainColor, + textAlign: isSolidColorStyle ? 'left' : undefined, + style, + ...attributes, + }; + }, +}; + +const v1 = { + attributes: { + ...blockAttributes, + }, + save( { attributes } ) { + const { value, citation } = attributes; + return ( +
+ + { ! RichText.isEmpty( citation ) && ( + + ) } +
+ ); + }, + migrate( { value, ...attributes } ) { + return { + value: multilineToInline( value ), + ...attributes, + }; + }, +}; + +const v0 = { + attributes: { + ...blockAttributes, + citation: { + type: 'string', + source: 'html', + selector: 'footer', + }, + align: { + type: 'string', + default: 'none', }, }, -]; -export default deprecated; + save( { attributes } ) { + const { value, citation, align } = attributes; + + return ( +
+ + { ! RichText.isEmpty( citation ) && ( + + ) } +
+ ); + }, + migrate( { value, ...attributes } ) { + return { + value: multilineToInline( value ), + ...attributes, + }; + }, +}; + +/** + * New deprecations need to be placed first + * for them to have higher priority. + * + * Old deprecations may need to be updated as well. + * + * See block-deprecation.md + */ +export default [ v5, v4, v3, v2, v1, v0 ]; diff --git a/packages/block-library/src/pullquote/edit.js b/packages/block-library/src/pullquote/edit.js index 77a6f12b602716..637d83d5b42897 100644 --- a/packages/block-library/src/pullquote/edit.js +++ b/packages/block-library/src/pullquote/edit.js @@ -52,7 +52,7 @@ function PullQuoteEdit( {
setAttributes( { diff --git a/packages/block-library/src/pullquote/edit.native.js b/packages/block-library/src/pullquote/edit.native.js index 06bb80bcfc3e8b..f43c82763ea7b3 100644 --- a/packages/block-library/src/pullquote/edit.native.js +++ b/packages/block-library/src/pullquote/edit.native.js @@ -83,7 +83,6 @@ function PullQuoteEdit( props ) {
setAttributes( { diff --git a/packages/block-library/src/pullquote/index.js b/packages/block-library/src/pullquote/index.js index d3694b7826940d..41b97f510c8ebc 100644 --- a/packages/block-library/src/pullquote/index.js +++ b/packages/block-library/src/pullquote/index.js @@ -22,12 +22,10 @@ export const settings = { example: { attributes: { value: - '

' + // translators: Quote serving as example for the Pullquote block. Attributed to Matt Mullenweg. __( 'One of the hardest things to do in technology is disrupt yourself.' - ) + - '

', + ), citation: __( 'Matt Mullenweg' ), }, }, diff --git a/packages/block-library/src/pullquote/save.js b/packages/block-library/src/pullquote/save.js index eddb1d1dbdf91b..26f6adc3eef05b 100644 --- a/packages/block-library/src/pullquote/save.js +++ b/packages/block-library/src/pullquote/save.js @@ -21,7 +21,7 @@ export default function save( { attributes } ) { } ) } >
- + { shouldShowCitation && ( ) } diff --git a/packages/block-library/src/pullquote/transforms.js b/packages/block-library/src/pullquote/transforms.js index ab2949c0afc975..a7f227f1aa2787 100644 --- a/packages/block-library/src/pullquote/transforms.js +++ b/packages/block-library/src/pullquote/transforms.js @@ -2,7 +2,7 @@ * WordPress dependencies */ import { createBlock } from '@wordpress/blocks'; -import { create, join, split, toHTMLString } from '@wordpress/rich-text'; +import { create, join, toHTMLString } from '@wordpress/rich-text'; const transforms = { from: [ @@ -17,9 +17,8 @@ const transforms = { attributes.map( ( { content } ) => create( { html: content } ) ), - '\u2028' + '\n' ), - multilineTag: 'p', } ), anchor: attributes.anchor, } ); @@ -30,7 +29,7 @@ const transforms = { blocks: [ 'core/heading' ], transform: ( { content, anchor } ) => { return createBlock( 'core/pullquote', { - value: `

${ content }

`, + value: content, anchor, } ); }, @@ -42,19 +41,14 @@ const transforms = { blocks: [ 'core/paragraph' ], transform: ( { value, citation } ) => { const paragraphs = []; - if ( value && value !== '

' ) { + if ( value ) { paragraphs.push( - ...split( - create( { html: value, multilineTag: 'p' } ), - '\u2028' - ).map( ( piece ) => - createBlock( 'core/paragraph', { - content: toHTMLString( { value: piece } ), - } ) - ) + createBlock( 'core/paragraph', { + content: value, + } ) ); } - if ( citation && citation !== '

' ) { + if ( citation ) { paragraphs.push( createBlock( 'core/paragraph', { content: citation, @@ -72,37 +66,27 @@ const transforms = { { type: 'block', blocks: [ 'core/heading' ], - transform: ( { value, citation, ...attrs } ) => { + transform: ( { value, citation } ) => { // If there is no pullquote content, use the citation as the // content of the resulting heading. A nonexistent citation // will result in an empty heading. - if ( value === '

' ) { + if ( ! value ) { return createBlock( 'core/heading', { content: citation, } ); } - const pieces = split( - create( { html: value, multilineTag: 'p' } ), - '\u2028' - ); const headingBlock = createBlock( 'core/heading', { - content: toHTMLString( { value: pieces[ 0 ] } ), + content: value, } ); - if ( ! citation && pieces.length === 1 ) { + if ( ! citation ) { return headingBlock; } - const quotePieces = pieces.slice( 1 ); - const pullquoteBlock = createBlock( 'core/pullquote', { - ...attrs, - citation, - value: toHTMLString( { - value: quotePieces.length - ? join( pieces.slice( 1 ), '\u2028' ) - : create(), - multilineTag: 'p', + return [ + headingBlock, + createBlock( 'core/heading', { + content: citation, } ), - } ); - return [ headingBlock, pullquoteBlock ]; + ]; }, }, ], diff --git a/packages/block-library/src/quote/transforms.js b/packages/block-library/src/quote/transforms.js index 6f922d1794e19e..d1f7b5523535d5 100644 --- a/packages/block-library/src/quote/transforms.js +++ b/packages/block-library/src/quote/transforms.js @@ -1,7 +1,7 @@ /** * WordPress dependencies */ -import { createBlock, parseWithAttributeSchema } from '@wordpress/blocks'; +import { createBlock } from '@wordpress/blocks'; const transforms = { from: [ @@ -17,19 +17,7 @@ const transforms = { fontSize, style, }, - parseWithAttributeSchema( value, { - type: 'array', - source: 'query', - selector: 'p', - query: { - content: { - type: 'string', - source: 'html', - }, - }, - } ).map( ( { content } ) => - createBlock( 'core/paragraph', { content } ) - ) + createBlock( 'core/paragraph', { content: value } ) ); }, }, @@ -106,10 +94,8 @@ const transforms = { innerBlocks ) => { const value = innerBlocks - .map( - ( { attributes } ) => `

${ attributes.content }

` - ) - .join( '' ); + .map( ( { attributes } ) => `${ attributes.content }` ) + .join( '
' ); return createBlock( 'core/pullquote', { value, citation, diff --git a/packages/e2e-tests/specs/editor/blocks/__snapshots__/quote.test.js.snap b/packages/e2e-tests/specs/editor/blocks/__snapshots__/quote.test.js.snap index 2478dc53f7cf74..4285e4c5dfc053 100644 --- a/packages/e2e-tests/specs/editor/blocks/__snapshots__/quote.test.js.snap +++ b/packages/e2e-tests/specs/editor/blocks/__snapshots__/quote.test.js.snap @@ -2,7 +2,7 @@ exports[`Quote can be converted to a pullquote 1`] = ` " -

one

two

cite
+

one
two

cite
" `; diff --git a/test/integration/fixtures/blocks/core__pullquote.json b/test/integration/fixtures/blocks/core__pullquote.json index f3b78a2c1dc2a0..7f4836eb815a09 100644 --- a/test/integration/fixtures/blocks/core__pullquote.json +++ b/test/integration/fixtures/blocks/core__pullquote.json @@ -3,7 +3,7 @@ "name": "core/pullquote", "isValid": true, "attributes": { - "value": "

Testing pullquote block...

", + "value": "Testing pullquote block...", "citation": "...with a caption" }, "innerBlocks": [] diff --git a/test/integration/fixtures/blocks/core__pullquote__custom-colors.json b/test/integration/fixtures/blocks/core__pullquote__custom-colors.json index 6b418804728a0b..e4e5e8fad25d0d 100644 --- a/test/integration/fixtures/blocks/core__pullquote__custom-colors.json +++ b/test/integration/fixtures/blocks/core__pullquote__custom-colors.json @@ -3,7 +3,7 @@ "name": "core/pullquote", "isValid": true, "attributes": { - "value": "

pullquote

", + "value": "pullquote", "citation": "citation", "textAlign": "right", "className": "is-style-default", diff --git a/test/integration/fixtures/blocks/core__pullquote__custom-colors__deprecated-4.json b/test/integration/fixtures/blocks/core__pullquote__custom-colors__deprecated-4.json index adcf4953e3cfb7..f66461afecbc1d 100644 --- a/test/integration/fixtures/blocks/core__pullquote__custom-colors__deprecated-4.json +++ b/test/integration/fixtures/blocks/core__pullquote__custom-colors__deprecated-4.json @@ -9,7 +9,7 @@ "color": "#2207d0" } }, - "value": "

Pullquote custom color

", + "value": "Pullquote custom color", "citation": "my citation", "textColor": "subtle-background" }, diff --git a/test/integration/fixtures/blocks/core__pullquote__deprecated-1.json b/test/integration/fixtures/blocks/core__pullquote__deprecated-1.json index b3b0f53cfdbbdb..5b2ecb98985b4d 100644 --- a/test/integration/fixtures/blocks/core__pullquote__deprecated-1.json +++ b/test/integration/fixtures/blocks/core__pullquote__deprecated-1.json @@ -3,7 +3,7 @@ "name": "core/pullquote", "isValid": true, "attributes": { - "value": "

Testing deprecated pullquote block...

", + "value": "Testing deprecated pullquote block...", "citation": "...with a caption", "align": "none" }, diff --git a/test/integration/fixtures/blocks/core__pullquote__deprecated-2.json b/test/integration/fixtures/blocks/core__pullquote__deprecated-2.json index e7023da2a2fd36..75529ae00dd0ec 100644 --- a/test/integration/fixtures/blocks/core__pullquote__deprecated-2.json +++ b/test/integration/fixtures/blocks/core__pullquote__deprecated-2.json @@ -3,7 +3,7 @@ "name": "core/pullquote", "isValid": true, "attributes": { - "value": "

Testing deprecated pullquote block...

", + "value": "Testing deprecated pullquote block...", "citation": "...with a caption" }, "innerBlocks": [] diff --git a/test/integration/fixtures/blocks/core__pullquote__deprecated-3.json b/test/integration/fixtures/blocks/core__pullquote__deprecated-3.json index a1c9270b9c76d5..c42557fe8b02fd 100644 --- a/test/integration/fixtures/blocks/core__pullquote__deprecated-3.json +++ b/test/integration/fixtures/blocks/core__pullquote__deprecated-3.json @@ -3,7 +3,7 @@ "name": "core/pullquote", "isValid": true, "attributes": { - "value": "

pullquote

", + "value": "pullquote", "citation": "", "textColor": "secondary", "style": { diff --git a/test/integration/fixtures/blocks/core__pullquote__deprecated-4.json b/test/integration/fixtures/blocks/core__pullquote__deprecated-4.json index 448ad102527cec..5a9ebaed5c3568 100644 --- a/test/integration/fixtures/blocks/core__pullquote__deprecated-4.json +++ b/test/integration/fixtures/blocks/core__pullquote__deprecated-4.json @@ -6,7 +6,7 @@ "className": "is-style-solid-color", "backgroundColor": "black", "textAlign": "left", - "value": "

pullquote

", + "value": "pullquote", "citation": "before block supports", "textColor": "white" }, diff --git a/test/integration/fixtures/blocks/core__pullquote__deprecated-5.html b/test/integration/fixtures/blocks/core__pullquote__deprecated-5.html new file mode 100644 index 00000000000000..87bd8b74f964c6 --- /dev/null +++ b/test/integration/fixtures/blocks/core__pullquote__deprecated-5.html @@ -0,0 +1,7 @@ + +
+
+

Testing pullquote block...

...with a caption +
+
+ diff --git a/test/integration/fixtures/blocks/core__pullquote__deprecated-5.json b/test/integration/fixtures/blocks/core__pullquote__deprecated-5.json new file mode 100644 index 00000000000000..7f4836eb815a09 --- /dev/null +++ b/test/integration/fixtures/blocks/core__pullquote__deprecated-5.json @@ -0,0 +1,11 @@ +[ + { + "name": "core/pullquote", + "isValid": true, + "attributes": { + "value": "Testing pullquote block...", + "citation": "...with a caption" + }, + "innerBlocks": [] + } +] diff --git a/test/integration/fixtures/blocks/core__pullquote__deprecated-5.parsed.json b/test/integration/fixtures/blocks/core__pullquote__deprecated-5.parsed.json new file mode 100644 index 00000000000000..ec2a278ba87bd3 --- /dev/null +++ b/test/integration/fixtures/blocks/core__pullquote__deprecated-5.parsed.json @@ -0,0 +1,11 @@ +[ + { + "blockName": "core/pullquote", + "attrs": {}, + "innerBlocks": [], + "innerHTML": "\n
\n
\n

Testing pullquote block...

...with a caption\n
\n
\n", + "innerContent": [ + "\n
\n
\n

Testing pullquote block...

...with a caption\n
\n
\n" + ] + } +] diff --git a/test/integration/fixtures/blocks/core__pullquote__deprecated-5.serialized.html b/test/integration/fixtures/blocks/core__pullquote__deprecated-5.serialized.html new file mode 100644 index 00000000000000..6ef3209575aeba --- /dev/null +++ b/test/integration/fixtures/blocks/core__pullquote__deprecated-5.serialized.html @@ -0,0 +1,3 @@ + +

Testing pullquote block...

...with a caption
+ diff --git a/test/integration/fixtures/blocks/core__pullquote__multi-paragraph.html b/test/integration/fixtures/blocks/core__pullquote__deprecated-5__multi-paragraph.html similarity index 100% rename from test/integration/fixtures/blocks/core__pullquote__multi-paragraph.html rename to test/integration/fixtures/blocks/core__pullquote__deprecated-5__multi-paragraph.html diff --git a/test/integration/fixtures/blocks/core__pullquote__multi-paragraph.json b/test/integration/fixtures/blocks/core__pullquote__deprecated-5__multi-paragraph.json similarity index 63% rename from test/integration/fixtures/blocks/core__pullquote__multi-paragraph.json rename to test/integration/fixtures/blocks/core__pullquote__deprecated-5__multi-paragraph.json index 7a910d45ad2454..27f956b801db22 100644 --- a/test/integration/fixtures/blocks/core__pullquote__multi-paragraph.json +++ b/test/integration/fixtures/blocks/core__pullquote__deprecated-5__multi-paragraph.json @@ -3,7 +3,7 @@ "name": "core/pullquote", "isValid": true, "attributes": { - "value": "

Paragraph one

Paragraph two

", + "value": "Paragraph one
Paragraph two", "citation": "by whomever" }, "innerBlocks": [] diff --git a/test/integration/fixtures/blocks/core__pullquote__multi-paragraph.parsed.json b/test/integration/fixtures/blocks/core__pullquote__deprecated-5__multi-paragraph.parsed.json similarity index 100% rename from test/integration/fixtures/blocks/core__pullquote__multi-paragraph.parsed.json rename to test/integration/fixtures/blocks/core__pullquote__deprecated-5__multi-paragraph.parsed.json diff --git a/test/integration/fixtures/blocks/core__pullquote__multi-paragraph.serialized.html b/test/integration/fixtures/blocks/core__pullquote__deprecated-5__multi-paragraph.serialized.html similarity index 55% rename from test/integration/fixtures/blocks/core__pullquote__multi-paragraph.serialized.html rename to test/integration/fixtures/blocks/core__pullquote__deprecated-5__multi-paragraph.serialized.html index 333b051f197287..ff0af0251aa39a 100644 --- a/test/integration/fixtures/blocks/core__pullquote__multi-paragraph.serialized.html +++ b/test/integration/fixtures/blocks/core__pullquote__deprecated-5__multi-paragraph.serialized.html @@ -1,3 +1,3 @@ -

Paragraph one

Paragraph two

by whomever
+

Paragraph one
Paragraph two

by whomever
diff --git a/test/integration/fixtures/blocks/core__pullquote__deprecated-main-color.json b/test/integration/fixtures/blocks/core__pullquote__deprecated-main-color.json index 4a84ef50c2262a..3e1cf19a8d5dbb 100644 --- a/test/integration/fixtures/blocks/core__pullquote__deprecated-main-color.json +++ b/test/integration/fixtures/blocks/core__pullquote__deprecated-main-color.json @@ -9,7 +9,7 @@ "color": "#2207d0" } }, - "value": "

Pullquote custom color

", + "value": "Pullquote custom color", "citation": "my citation", "textColor": "subtle-background" },