Skip to content

Commit

Permalink
Fix character newlines in pre (#13799)
Browse files Browse the repository at this point in the history
* Fix character newlines in pre

* Add e2e test
  • Loading branch information
ellatrix authored Feb 20, 2019
1 parent 1a0f88d commit 2a37333
Showing 3 changed files with 50 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/block-library/src/preformatted/index.js
Original file line number Diff line number Diff line change
@@ -68,7 +68,7 @@ export const settings = {
return (
<RichText
tagName="pre"
value={ content }
value={ content.replace( /\n/g, '<br>' ) }
onChange={ ( nextContent ) => {
setAttributes( {
content: nextContent,
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Preformatted should preserve character newlines 1`] = `
"<!-- wp:html -->
<pre>1
2</pre>
<!-- /wp:html -->"
`;

exports[`Preformatted should preserve character newlines 2`] = `
"<!-- wp:preformatted -->
<pre class=\\"wp-block-preformatted\\">0<br>1<br>2</pre>
<!-- /wp:preformatted -->"
`;
35 changes: 35 additions & 0 deletions packages/e2e-tests/specs/blocks/preformatted.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/**
* WordPress dependencies
*/
import {
getEditedPostContent,
createNewPost,
insertBlock,
clickButton,
} from '@wordpress/e2e-test-utils';

describe( 'Preformatted', () => {
beforeEach( async () => {
await createNewPost();
} );

it( 'should preserve character newlines', async () => {
await insertBlock( 'Custom HTML' );
await page.keyboard.type( '<pre>1' );
await page.keyboard.press( 'Enter' );
await page.keyboard.type( '2</pre>' );

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

await page.keyboard.press( 'Escape' );
await page.click( 'button[aria-label="More options"]' );
await clickButton( 'Convert to Blocks' );
// Once it's edited, it should be saved as BR tags.
await page.keyboard.type( '0' );
await page.keyboard.press( 'Enter' );
await page.click( 'button[aria-label="More options"]' );
await clickButton( 'Edit as HTML' );

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

0 comments on commit 2a37333

Please sign in to comment.