diff --git a/.gitignore b/.gitignore index fd1b80cce6b..a076a1193fe 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ mrgit.json build/ !packages/ckeditor5-build-*/build +.DS_Store diff --git a/packages/ckeditor5-paste-from-office/src/filters/space.js b/packages/ckeditor5-paste-from-office/src/filters/space.js index 34d1dee122d..7fdab4fecb2 100644 --- a/packages/ckeditor5-paste-from-office/src/filters/space.js +++ b/packages/ckeditor5-paste-from-office/src/filters/space.js @@ -39,9 +39,13 @@ export function normalizeSpacing( htmlString ) { */ export function normalizeSpacerunSpans( htmlDocument ) { htmlDocument.querySelectorAll( 'span[style*=spacerun]' ).forEach( el => { - const innerTextLength = el.innerText.length || 0; + // For paste contents from WPS Office, the span's inner text is not all of spaces or blank, + // so we should keep the origin contents, or replace ONLY space characters. + if ( el.innerText.trim().length === 0 ) { + const innerTextLength = el.innerText.length || 0; - el.innerHTML = Array( innerTextLength + 1 ).join( '\u00A0 ' ).substr( 0, innerTextLength ); + el.innerHTML = Array( innerTextLength + 1 ).join( '\u00A0 ' ).substr( 0, innerTextLength ); + } } ); } diff --git a/packages/ckeditor5-paste-from-office/tests/filters/space.js b/packages/ckeditor5-paste-from-office/tests/filters/space.js index 9424cccf337..1e57d87fa2c 100644 --- a/packages/ckeditor5-paste-from-office/tests/filters/space.js +++ b/packages/ckeditor5-paste-from-office/tests/filters/space.js @@ -136,6 +136,23 @@ describe( 'PasteFromOffice - filters', () => { expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.equal( expected ); } ); + + it( 'should not normalize spaces inside special "span.spacerun" elements pasted from WPS', () => { + const input = '

' + + '感受非遗魅力,弘扬传统文化,

'; + + const expected = input; + + const domParser = new DOMParser(); + const htmlDocument = domParser.parseFromString( input, 'text/html' ); + + expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.equal( expected ); + + normalizeSpacerunSpans( htmlDocument ); + + expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.equal( expected ); + } ); } ); } ); } );