Skip to content

Commit

Permalink
Paste: strip HTML formatting space for inline text (#19043)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Dec 10, 2019
1 parent 23f9795 commit 6ad16aa
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions packages/blocks/src/api/raw-handling/paste-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const { console } = window;
function filterInlineHTML( HTML ) {
HTML = deepFilterHTML( HTML, [ googleDocsUIDRemover, phrasingContentReducer, commentRemover ] );
HTML = removeInvalidHTML( HTML, getPhrasingContentSchema( 'paste' ), { inline: true } );
HTML = deepFilterHTML( HTML, [ htmlFormattingRemover, brRemover ] );

// Allows us to ask for this information when we get a report.
console.log( 'Processed inline HTML:\n\n', HTML );
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ exports[`Blocks raw handling pasteHandler should remove extra blank lines 1`] =
<!-- /wp:paragraph -->"
`;

exports[`Blocks raw handling pasteHandler should strip HTML formatting space from inline text 1`] = `"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent a elit eget tortor molestie egestas. Donec pretium urna vitae mattis imperdiet. Praesent et lorem iaculis, volutpat odio vitae, ornare lacus. Donec ut felis tristique, pharetra erat id, viverra justo. Integer sit amet elementum arcu, eget pharetra felis. In malesuada enim est, sed placerat nulla feugiat at. Vestibulum feugiat vitae elit sit amet tincidunt. Pellentesque finibus sed dolor non facilisis. Curabitur accumsan ante ac hendrerit vestibulum."`;

exports[`Blocks raw handling pasteHandler should strip some text-level elements 1`] = `
"<!-- wp:paragraph -->
<p>This is ncorect</p>
Expand Down
6 changes: 6 additions & 0 deletions test/integration/blocks-raw-handling.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,12 @@ describe( 'Blocks raw handling', () => {
const HTML = readFile( path.join( __dirname, 'fixtures/windows.html' ) );
expect( serialize( pasteHandler( { HTML } ) ) ).toMatchSnapshot();
} );

it( 'should strip HTML formatting space from inline text', () => {
const HTML = readFile( path.join( __dirname, 'fixtures/inline-with-html-formatting-space.html' ) );
expect( pasteHandler( { HTML } ) ).toMatchSnapshot();
expect( console ).toHaveLogged();
} );
} );
} );

Expand Down
11 changes: 11 additions & 0 deletions test/integration/fixtures/inline-with-html-formatting-space.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<html><body>
<!--StartFragment-->Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent a elit
eget tortor molestie egestas. Donec pretium urna vitae mattis
imperdiet. Praesent et lorem iaculis, volutpat odio vitae, ornare lacus.
Donec ut felis tristique, pharetra erat id, viverra justo. Integer sit
amet elementum arcu, eget pharetra felis. In malesuada enim est, sed
placerat nulla feugiat at. Vestibulum feugiat vitae elit sit amet
tincidunt. Pellentesque finibus sed dolor non facilisis. Curabitur
accumsan ante ac hendrerit vestibulum.
<!--EndFragment-->
</body>

0 comments on commit 6ad16aa

Please sign in to comment.