From ac92f21388b08b4b7a4ad09e69619b4223ee8ea8 Mon Sep 17 00:00:00 2001 From: Ella van Durpe Date: Tue, 10 Dec 2019 18:17:09 +0100 Subject: [PATCH] Paste: strip HTML formatting space for inline text --- packages/blocks/src/api/raw-handling/paste-handler.js | 1 + .../__snapshots__/blocks-raw-handling.test.js.snap | 2 ++ test/integration/blocks-raw-handling.test.js | 6 ++++++ .../fixtures/inline-with-html-formatting-space.html | 11 +++++++++++ 4 files changed, 20 insertions(+) create mode 100644 test/integration/fixtures/inline-with-html-formatting-space.html diff --git a/packages/blocks/src/api/raw-handling/paste-handler.js b/packages/blocks/src/api/raw-handling/paste-handler.js index 12eb25e72173c..f126e050c15c0 100644 --- a/packages/blocks/src/api/raw-handling/paste-handler.js +++ b/packages/blocks/src/api/raw-handling/paste-handler.js @@ -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 ); diff --git a/test/integration/__snapshots__/blocks-raw-handling.test.js.snap b/test/integration/__snapshots__/blocks-raw-handling.test.js.snap index 4197d9cfaffa6..9cefe8bffb6fd 100644 --- a/test/integration/__snapshots__/blocks-raw-handling.test.js.snap +++ b/test/integration/__snapshots__/blocks-raw-handling.test.js.snap @@ -10,6 +10,8 @@ exports[`Blocks raw handling pasteHandler should remove extra blank lines 1`] = " `; +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`] = ` "

This is ncorect

diff --git a/test/integration/blocks-raw-handling.test.js b/test/integration/blocks-raw-handling.test.js index fd2255b1bd096..d042702d37b0d 100644 --- a/test/integration/blocks-raw-handling.test.js +++ b/test/integration/blocks-raw-handling.test.js @@ -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(); + } ); } ); } ); diff --git a/test/integration/fixtures/inline-with-html-formatting-space.html b/test/integration/fixtures/inline-with-html-formatting-space.html new file mode 100644 index 0000000000000..3e51738cab59e --- /dev/null +++ b/test/integration/fixtures/inline-with-html-formatting-space.html @@ -0,0 +1,11 @@ + + 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. + +