Skip to content

Commit

Permalink
Fixed quote paragraph transformations.
Browse files Browse the repository at this point in the history
Before when transforming a quote into a paragraph the result was a a paragraph and the remaining quote. Now the quote is transformed into several paragraphs. The logic was also simplified.
  • Loading branch information
jorgefilipecosta committed Dec 4, 2017
1 parent 9bfd837 commit bd6776a
Showing 1 changed file with 11 additions and 27 deletions.
38 changes: 11 additions & 27 deletions blocks/library/quote/index.js
@@ -1,7 +1,7 @@
/**
* External dependencies
*/
import { isString } from 'lodash';
import { isString, get } from 'lodash';

/**
* WordPress dependencies
Expand Down Expand Up @@ -101,33 +101,17 @@ registerBlockType( 'core/quote', {
{
type: 'block',
blocks: [ 'core/paragraph' ],
transform: ( { value, citation, ...attrs } ) => {
const textElement = value[ 0 ];
if ( ! textElement ) {
return createBlock( 'core/paragraph', {
content: citation,
} );
transform: ( { value, citation } ) => {
// transforming an empty quote
if ( ( ! value || ! value.length ) && ! citation ) {
return createBlock( 'core/paragraph' );
}
const textContent = isString( textElement.children ) ?
textElement.children :
textElement.children.props.children;
if ( Array.isArray( value ) || citation ) {
const text = createBlock( 'core/paragraph', {
content: textContent,
} );
const quote = createBlock( 'core/quote', {
...attrs,
citation,
value: Array.isArray( value ) ?
value.slice( 1 ) :
[],
} );

return [ text, quote ];
}
return createBlock( 'core/paragraph', {
content: textContent,
} );
// transforming a quote with content
return ( value || [] ).map( item => createBlock( 'core/paragraph', {
content: [ get( item, 'children.props.children', '' ) ],
} ) ).concat( citation ? createBlock( 'core/paragraph', {
content: citation,
} ) : [] );
},
},
{
Expand Down

0 comments on commit bd6776a

Please sign in to comment.