Skip to content

Commit

Permalink
Stop removing tables on paste (#2199)
Browse files Browse the repository at this point in the history
This removes the code that was stripping table elements on paste. They used to cause an exception on paste, but are now working fine.
  • Loading branch information
georgeh authored Aug 4, 2017
1 parent 12c6401 commit 20be975
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 16 deletions.
3 changes: 1 addition & 2 deletions blocks/api/paste.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ import { nodetypes } from '@wordpress/utils';
import { createBlock } from './factory';
import { getBlockTypes, getUnknownTypeHandler } from './registration';
import { parseBlockAttributes } from './parser';
import convertTables from './paste/convert-tables';
import stripAttributes from './paste/strip-attributes';
import removeSpans from './paste/remove-spans';

Expand Down Expand Up @@ -80,7 +79,7 @@ export function normaliseToBlockLevelNodes( nodes ) {
}

export default function( nodes ) {
const prepare = compose( [ normaliseToBlockLevelNodes, removeSpans, stripAttributes, convertTables ] );
const prepare = compose( [ normaliseToBlockLevelNodes, removeSpans, stripAttributes ] );

return prepare( nodes ).map( ( node ) => {
const block = getBlockTypes().reduce( ( acc, blockType ) => {
Expand Down
10 changes: 0 additions & 10 deletions blocks/api/paste/convert-tables.js

This file was deleted.

12 changes: 8 additions & 4 deletions blocks/api/paste/strip-attributes.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { ELEMENT_NODE } from 'utils/nodetypes';

export default function( nodes ) {
// MUTATION!
nodes.forEach( deepAttributeStrip );
return nodes;
}

function deepAttributeStrip( node ) {
node.removeAttribute( 'style' );
node.removeAttribute( 'class' );
node.removeAttribute( 'id' );
Array.from( node.children ).forEach( deepAttributeStrip );
if ( ELEMENT_NODE === node.nodeType ) {
node.removeAttribute( 'style' );
node.removeAttribute( 'class' );
node.removeAttribute( 'id' );
Array.from( node.children ).forEach( deepAttributeStrip );
}
}

0 comments on commit 20be975

Please sign in to comment.