Skip to content

Commit

Permalink
Paste: ignore Google Docs UID tag (#14138)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored and youknowriad committed Mar 6, 2019
1 parent bc3f63e commit 82644f1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
12 changes: 12 additions & 0 deletions packages/blocks/src/api/raw-handling/google-docs-uid-remover.js
Original file line number Diff line number Diff line change
@@ -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 );
}
4 changes: 3 additions & 1 deletion packages/blocks/src/api/raw-handling/paste-handler.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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.
Expand Down Expand Up @@ -191,6 +192,7 @@ export function pasteHandler( { HTML = '', plainText = '', mode = 'AUTO', tagNam
}

const filters = [
googleDocsUIDRemover,
msListConverter,
headRemover,
listReducer,
Expand Down
20 changes: 20 additions & 0 deletions test/integration/blocks-raw-handling.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,26 @@ describe( 'Blocks raw handling', () => {
expect( console ).toHaveLogged();
} );

it( 'should ignore Google Docs UID tag', () => {
const filtered = pasteHandler( {
HTML: '<b id="docs-internal-guid-0"><em>test</em></b>',
mode: 'AUTO',
} ).map( getBlockContent ).join( '' );

expect( filtered ).toBe( '<p><em>test</em></p>' );
expect( console ).toHaveLogged();
} );

it( 'should ignore Google Docs UID tag in inline mode', () => {
const filtered = pasteHandler( {
HTML: '<b id="docs-internal-guid-0"><em>test</em></b>',
mode: 'INLINE',
} );

expect( filtered ).toBe( '<em>test</em>' );
expect( console ).toHaveLogged();
} );

it( 'should parse Markdown', () => {
const filtered = pasteHandler( {
HTML: '* one<br>* two<br>* three',
Expand Down

0 comments on commit 82644f1

Please sign in to comment.