Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

List Block: Do not split on line breaks when multiple blocks are transformed #13832

Merged
merged 1 commit into from
Feb 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions packages/block-library/src/list/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,17 @@ export const settings = {
transform: ( blockAttributes ) => {
return createBlock( 'core/list', {
values: toHTMLString( {
value: join( blockAttributes.map( ( { content } ) =>
replace( create( { html: content } ), /\n/g, LINE_SEPARATOR )
), LINE_SEPARATOR ),
value: join( blockAttributes.map( ( { content } ) => {
const value = create( { html: content } );

if ( blockAttributes.length > 1 ) {
return value;
}

// When converting only one block, transform
// every line to a list item.
return replace( value, /\n/g, LINE_SEPARATOR );
} ), LINE_SEPARATOR ),
multilineTag: 'li',
} ),
} );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,12 @@ exports[`List should insert a line break on shift+enter in a non trailing list i
<!-- /wp:list -->"
`;

exports[`List should not transform lines in block when transforming multiple blocks 1`] = `
"<!-- wp:list -->
<ul><li>one<br>...</li><li>two</li></ul>
<!-- /wp:list -->"
`;

exports[`List should outdent with children 1`] = `
"<!-- wp:list -->
<ul><li>a<ul><li>b<ul><li>c</li></ul></li></ul></li></ul>
Expand Down
15 changes: 15 additions & 0 deletions packages/e2e-tests/specs/blocks/list.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,21 @@ describe( 'List', () => {
expect( await getEditedPostContent() ).toMatchSnapshot();
} );

it( 'should not transform lines in block when transforming multiple blocks', async () => {
await clickBlockAppender();
await page.keyboard.type( 'one' );
await pressKeyWithModifier( 'shift', 'Enter' );
await page.keyboard.type( '...' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( 'two' );
await page.keyboard.down( 'Shift' );
await page.click( '[data-type="core/paragraph"]' );
await page.keyboard.up( 'Shift' );
await transformBlockTo( 'List' );

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

it( 'can be converted to paragraphs', async () => {
await insertBlock( 'List' );
await page.keyboard.type( 'one' );
Expand Down