Skip to content

Commit

Permalink
Take into account citation when transform a quote to paragraph (#10685)
Browse files Browse the repository at this point in the history
  • Loading branch information
nosolosw authored Oct 17, 2018
1 parent 237d6ed commit a22cbbb
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 14 deletions.
30 changes: 25 additions & 5 deletions packages/block-library/src/quote/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,33 @@ export const settings = {
{
type: 'block',
blocks: [ 'core/paragraph' ],
transform: ( { value } ) =>
split( create( { html: value, multilineTag: 'p' } ), '\u2028' )
.map( ( piece ) =>
transform: ( { value, citation } ) => {
const paragraphs = [];
if ( value ) {
paragraphs.push(
...split( create( { html: value, multilineTag: 'p' } ), '\u2028' )
.map( ( piece ) =>
createBlock( 'core/paragraph', {
content: toHTMLString( piece ),
} )
)
);
}
if ( citation ) {
paragraphs.push(
createBlock( 'core/paragraph', {
content: toHTMLString( piece ),
content: citation,
} )
),
);
}

if ( paragraphs.length === 0 ) {
return createBlock( 'core/paragraph', {
content: '',
} );
}
return paragraphs;
},
},

{
Expand Down
24 changes: 23 additions & 1 deletion test/e2e/specs/blocks/__snapshots__/quote.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,35 @@ exports[`Quote can be converted to headings 3`] = `
<!-- /wp:heading -->"
`;
exports[`Quote can be converted to paragraphs 1`] = `
exports[`Quote can be converted to paragraphs and renders a paragraph for the cite, if it exists 1`] = `
"<!-- wp:paragraph -->
<p>one</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>two</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>cite</p>
<!-- /wp:paragraph -->"
`;
exports[`Quote can be converted to paragraphs and renders a void paragraph if both the cite and quote are void 1`] = `""`;
exports[`Quote can be converted to paragraphs and renders one paragraph block per <p> within quote 1`] = `
"<!-- wp:paragraph -->
<p>one</p>
<!-- /wp:paragraph -->
<!-- wp:paragraph -->
<p>two</p>
<!-- /wp:paragraph -->"
`;
exports[`Quote can be converted to paragraphs and renders only one paragraph for the cite, if the quote is void 1`] = `
"<!-- wp:paragraph -->
<p>cite</p>
<!-- /wp:paragraph -->"
`;
Expand Down
46 changes: 38 additions & 8 deletions test/e2e/specs/blocks/quote.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,44 @@ describe( 'Quote', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'can be converted to paragraphs', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await convertBlock( 'Paragraph' );

expect( await getEditedPostContent() ).toMatchSnapshot();
describe( 'can be converted to paragraphs', async () => {
it( 'and renders one paragraph block per <p> within quote', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await convertBlock( 'Paragraph' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'and renders a paragraph for the cite, if it exists', async () => {
await insertBlock( 'Quote' );
await page.keyboard.type( 'one' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await page.keyboard.press( 'Tab' );
await page.keyboard.type( 'cite' );
await convertBlock( 'Paragraph' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'and renders only one paragraph for the cite, if the quote is void', async () => {
await insertBlock( 'Quote' );
await page.keyboard.press( 'Tab' );
await page.keyboard.type( 'cite' );
await convertBlock( 'Paragraph' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'and renders a void paragraph if both the cite and quote are void', async () => {
await insertBlock( 'Quote' );
await convertBlock( 'Paragraph' );

expect( await getEditedPostContent() ).toMatchSnapshot();
} );
} );

it( 'can be created by converting a heading', async () => {
Expand Down

0 comments on commit a22cbbb

Please sign in to comment.