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: ignore Google Docs UID tag #14138

Merged
merged 1 commit into from
Feb 27, 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
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