Skip to content

Commit

Permalink
Remove filterString param
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix committed Jan 30, 2019
1 parent 5ba90fd commit ed4200d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 30 deletions.
1 change: 0 additions & 1 deletion packages/editor/src/components/rich-text/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ export class RichText extends Component {
removeNode: ( node ) => node.getAttribute( 'data-mce-bogus' ) === 'all',
unwrapNode: ( node ) => !! node.getAttribute( 'data-mce-bogus' ),
removeAttribute: ( attribute ) => attribute.indexOf( 'data-mce-' ) === 0,
filterString: ( string ) => string.replace( '\uFEFF', '' ),
prepareEditableTree: this.props.prepareEditableTree,
} );
}
Expand Down
40 changes: 12 additions & 28 deletions packages/rich-text/src/create.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import { createElement } from './create-element';
import {
LINE_SEPARATOR,
OBJECT_REPLACEMENT_CHARACTER,
ZERO_WIDTH_NO_BREAK_SPACE,
} from './special-characters';

/**
Expand Down Expand Up @@ -102,8 +103,6 @@ function toFormat( { type, attributes } ) {
* given node should be removed.
* @param {?Function} $1.unwrapNode Function to declare whether the
* given node should be unwrapped.
* @param {?Function} $1.filterString Function to filter the given
* string.
* @param {?Function} $1.removeAttribute Wether to remove an attribute
* based on the name.
*
Expand All @@ -118,7 +117,6 @@ export function create( {
multilineWrapperTags,
removeNode,
unwrapNode,
filterString,
removeAttribute,
} = {} ) {
if ( typeof text === 'string' && text.length > 0 ) {
Expand All @@ -142,7 +140,6 @@ export function create( {
range,
removeNode,
unwrapNode,
filterString,
removeAttribute,
} );
}
Expand All @@ -154,7 +151,6 @@ export function create( {
multilineWrapperTags,
removeNode,
unwrapNode,
filterString,
removeAttribute,
} );
}
Expand Down Expand Up @@ -252,6 +248,15 @@ function filterRange( node, range, filter ) {
return { startContainer, startOffset, endContainer, endOffset };
}

function filterString( string ) {
// Reduce any whitespace used for HTML formatting to one space
// character, because it will also be displayed as such by the browser.
string = string.replace( /[\n\r\t]+/g, ' ' );
string = string.replace( new RegExp( ZERO_WIDTH_NO_BREAK_SPACE, 'g' ), '' );

return string;
}

/**
* Creates a Rich Text value from a DOM element and range.
*
Expand All @@ -266,8 +271,6 @@ function filterRange( node, range, filter ) {
* given node should be removed.
* @param {?Function} $1.unwrapNode Function to declare whether the
* given node should be unwrapped.
* @param {?Function} $1.filterString Function to filter the given
* string.
* @param {?Function} $1.removeAttribute Wether to remove an attribute
* based on the name.
*
Expand All @@ -281,7 +284,6 @@ function createFromElement( {
currentWrapperTags = [],
removeNode,
unwrapNode,
filterString,
removeAttribute,
} ) {
const accumulator = createEmptyValue();
Expand All @@ -297,26 +299,14 @@ function createFromElement( {

const length = element.childNodes.length;

const filterStringComplete = ( string ) => {
// Reduce any whitespace used for HTML formatting to one space
// character, because it will also be displayed as such by the browser.
string = string.replace( /[\n\r\t]+/g, ' ' );

if ( filterString ) {
string = filterString( string );
}

return string;
};

// Optimise for speed.
for ( let index = 0; index < length; index++ ) {
const node = element.childNodes[ index ];
const type = node.nodeName.toLowerCase();

if ( node.nodeType === TEXT_NODE ) {
const text = filterStringComplete( node.nodeValue );
range = filterRange( node, range, filterStringComplete );
const text = filterString( node.nodeValue );
range = filterRange( node, range, filterString );
accumulateSelection( accumulator, node, range, { text } );
accumulator.text += text;
// Create a sparse array of the same length as `text`, in which
Expand Down Expand Up @@ -376,7 +366,6 @@ function createFromElement( {
multilineWrapperTags,
removeNode,
unwrapNode,
filterString,
removeAttribute,
currentWrapperTags: [ ...currentWrapperTags, format ],
} );
Expand All @@ -389,7 +378,6 @@ function createFromElement( {
multilineWrapperTags,
removeNode,
unwrapNode,
filterString,
removeAttribute,
} );
}
Expand Down Expand Up @@ -462,8 +450,6 @@ function createFromElement( {
* given node should be removed.
* @param {?Function} $1.unwrapNode Function to declare whether the
* given node should be unwrapped.
* @param {?Function} $1.filterString Function to filter the given
* string.
* @param {?Function} $1.removeAttribute Wether to remove an attribute
* based on the name.
* @param {boolean} $1.currentWrapperTags Whether to prepend a line
Expand All @@ -478,7 +464,6 @@ function createFromMultilineElement( {
multilineWrapperTags,
removeNode,
unwrapNode,
filterString,
removeAttribute,
currentWrapperTags = [],
} ) {
Expand Down Expand Up @@ -506,7 +491,6 @@ function createFromMultilineElement( {
currentWrapperTags,
removeNode,
unwrapNode,
filterString,
removeAttribute,
} );

Expand Down
2 changes: 1 addition & 1 deletion packages/rich-text/src/special-characters.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export const LINE_SEPARATOR = '\u2028';
export const OBJECT_REPLACEMENT_CHARACTER = '\ufffc';
export const ZERO_WIDTH_NO_BREAK_SPACE = '\uFEFF';
export const ZERO_WIDTH_NO_BREAK_SPACE = '\ufeff';

0 comments on commit ed4200d

Please sign in to comment.