Răsfoiți Sursa

Handle additional 'spacerun spans' with mixed whitespaces.

Krzysztof Krztoń 7 ani în urmă
părinte
comite
2d70f07a9f

+ 2 - 1
packages/ckeditor5-paste-from-office/src/filters/space.js

@@ -18,9 +18,10 @@
  */
 export function normalizeSpacing( htmlString ) {
 	return normalizeSafariSpaceSpans( normalizeSafariSpaceSpans( htmlString ) ) // Run normalization two times to cover nested spans.
+		.replace( /(<span style=['"]mso-spacerun:yes['"]>[^\S\r\n]*)[\r\n]+(\s*<\/span>)/g, '$1$2' )
+		.replace( /<span style=['"]mso-spacerun:yes['"]><\/span>/g, '' )
 		.replace( / <\//g, '\u00A0</' )
 		.replace( / <o:p><\/o:p>/g, '\u00A0<o:p></o:p>' )
-		.replace( /(<span style=['"]mso-spacerun:yes['"]>[^\S\r\n]+)[\r\n]+(\s*<\/span>)/g, '$1$2' )
 		.replace( />(\s*(\r\n?|\n)\s*)+</g, '><' );
 }
 

+ 31 - 3
packages/ckeditor5-paste-from-office/tests/filters/space.js

@@ -24,9 +24,37 @@ describe( 'Filters', () => {
 				expect( normalizeSpacing( input ) ).to.equal( expected );
 			} );
 
-			it( 'should remove newlines from spacerun spans', () => {
-				const input = '<span style=\'mso-spacerun:yes\'>  \r\n</span>';
-				const expected = '<span style=\'mso-spacerun:yes\'>  </span>';
+			it( 'should remove newlines from spacerun spans #1', () => {
+				const input = '<span style=\'mso-spacerun:yes\'>  \n</span>';
+				const expected = '<span style=\'mso-spacerun:yes\'> \u00A0</span>';
+
+				expect( normalizeSpacing( input ) ).to.equal( expected );
+			} );
+
+			it( 'should remove newlines from spacerun spans #2', () => {
+				const input = '<span style=\'mso-spacerun:yes\'> \r\n</span>';
+				const expected = '<span style=\'mso-spacerun:yes\'>\u00A0</span>';
+
+				expect( normalizeSpacing( input ) ).to.equal( expected );
+			} );
+
+			it( 'should remove newlines from spacerun spans #3', () => {
+				const input = '<span style=\'mso-spacerun:yes\'>  \r\n\n  </span>';
+				const expected = '<span style=\'mso-spacerun:yes\'>   \u00A0</span>';
+
+				expect( normalizeSpacing( input ) ).to.equal( expected );
+			} );
+
+			it( 'should remove newlines from spacerun spans #4', () => {
+				const input = '<span style=\'mso-spacerun:yes\'>\n\n\n  </span>';
+				const expected = '<span style=\'mso-spacerun:yes\'> \u00A0</span>';
+
+				expect( normalizeSpacing( input ) ).to.equal( expected );
+			} );
+
+			it( 'should remove newlines from spacerun spans #5', () => {
+				const input = '<span style=\'mso-spacerun:yes\'>\n\n</span>';
+				const expected = '';
 
 				expect( normalizeSpacing( input ) ).to.equal( expected );
 			} );