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

Paste: strip HTML formatting space for inline text #19043

Merged
merged 1 commit into from
Dec 10, 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
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>