diff --git a/packages/blocks/src/api/raw-handling/google-docs-uid-remover.js b/packages/blocks/src/api/raw-handling/google-docs-uid-remover.js new file mode 100644 index 00000000000000..adced320975d79 --- /dev/null +++ b/packages/blocks/src/api/raw-handling/google-docs-uid-remover.js @@ -0,0 +1,12 @@ +/** + * WordPress dependencies + */ +import { unwrap } from '@wordpress/dom'; + +export default function( node ) { + if ( ! node.id || node.id.indexOf( 'docs-internal-guid-' ) !== 0 ) { + return; + } + + unwrap( node ); +} diff --git a/packages/blocks/src/api/raw-handling/paste-handler.js b/packages/blocks/src/api/raw-handling/paste-handler.js index cc14ace649b5a8..b40164f549689b 100644 --- a/packages/blocks/src/api/raw-handling/paste-handler.js +++ b/packages/blocks/src/api/raw-handling/paste-handler.js @@ -22,6 +22,7 @@ import figureContentReducer from './figure-content-reducer'; import shortcodeConverter from './shortcode-converter'; import markdownConverter from './markdown-converter'; import iframeRemover from './iframe-remover'; +import googleDocsUIDRemover from './google-docs-uid-remover'; import { getPhrasingContentSchema } from './phrasing-content'; import { deepFilterHTML, @@ -43,7 +44,7 @@ const { console } = window; * @return {string} HTML only containing phrasing content. */ function filterInlineHTML( HTML ) { - HTML = deepFilterHTML( HTML, [ phrasingContentReducer ] ); + HTML = deepFilterHTML( HTML, [ googleDocsUIDRemover, phrasingContentReducer ] ); HTML = removeInvalidHTML( HTML, getPhrasingContentSchema(), { inline: true } ); // Allows us to ask for this information when we get a report. @@ -191,6 +192,7 @@ export function pasteHandler( { HTML = '', plainText = '', mode = 'AUTO', tagNam } const filters = [ + googleDocsUIDRemover, msListConverter, headRemover, listReducer, diff --git a/test/integration/blocks-raw-handling.spec.js b/test/integration/blocks-raw-handling.spec.js index 4e0b6c4d60b706..72426e00094fb8 100644 --- a/test/integration/blocks-raw-handling.spec.js +++ b/test/integration/blocks-raw-handling.spec.js @@ -36,6 +36,26 @@ describe( 'Blocks raw handling', () => { expect( console ).toHaveLogged(); } ); + it( 'should ignore Google Docs UID tag', () => { + const filtered = pasteHandler( { + HTML: 'test', + mode: 'AUTO', + } ).map( getBlockContent ).join( '' ); + + expect( filtered ).toBe( '
test
' ); + expect( console ).toHaveLogged(); + } ); + + it( 'should ignore Google Docs UID tag in inline mode', () => { + const filtered = pasteHandler( { + HTML: 'test', + mode: 'INLINE', + } ); + + expect( filtered ).toBe( 'test' ); + expect( console ).toHaveLogged(); + } ); + it( 'should parse Markdown', () => { const filtered = pasteHandler( { HTML: '* one