Skip to content
Closed
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,4 @@ mrgit.json

build/
!packages/ckeditor5-build-*/build
.DS_Store
8 changes: 6 additions & 2 deletions packages/ckeditor5-paste-from-office/src/filters/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}
} );
}

Expand Down
17 changes: 17 additions & 0 deletions packages/ckeditor5-paste-from-office/tests/filters/space.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = '<p class=MsoNormal ><span style="mso-spacerun:\'yes\';font-family:等线;' +
'mso-bidi-font-family:\'Times New Roman\';font-size:10.5000pt;mso-font-kerning:1.0000pt;" >' +
'<font face="等线" >感受非遗魅力,弘扬传统文化,</font></span></p>';

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 );
} );
} );
} );
} );