Explorar o código

Merge branch 'master' into i/5696

Aleksander Nowodzinski %!s(int64=6) %!d(string=hai) anos
pai
achega
99640aa410

+ 6 - 4
packages/ckeditor5-paste-from-office/docs/_snippets/features/build-paste-from-office-source.js

@@ -14,20 +14,22 @@ import Subscript from '@ckeditor/ckeditor5-basic-styles/src/subscript';
 import Superscript from '@ckeditor/ckeditor5-basic-styles/src/superscript';
 import Underline from '@ckeditor/ckeditor5-basic-styles/src/underline';
 import Font from '@ckeditor/ckeditor5-font/src/font';
-import Highlight from '@ckeditor/ckeditor5-highlight/src/highlight';
 import Indent from '@ckeditor/ckeditor5-indent/src/indent';
+import IndentBlock from '@ckeditor/ckeditor5-indent/src/indentblock';
+import ImageResize from '@ckeditor/ckeditor5-image/src/imageresize';
 
 ClassicEditor.builtinPlugins.push(
-	Alignment,
 	PasteFromOffice,
+	Alignment,
 	Code,
 	Strikethrough,
 	Subscript,
 	Superscript,
 	Underline,
 	Font,
-	Highlight,
-	Indent
+	Indent,
+	IndentBlock,
+	ImageResize,
 );
 
 window.ClassicEditor = ClassicEditor;

+ 9 - 3
packages/ckeditor5-paste-from-office/src/filters/list.js

@@ -201,9 +201,15 @@ function getListItemData( element ) {
 	const listStyle = element.getStyle( 'mso-list' );
 
 	if ( listStyle ) {
-		data.id = parseInt( listStyle.match( /(^|\s+)l(\d+)/i )[ 2 ] );
-		data.order = parseInt( listStyle.match( /\s*lfo(\d+)/i )[ 1 ] );
-		data.indent = parseInt( listStyle.match( /\s*level(\d+)/i )[ 1 ] );
+		const idMatch = listStyle.match( /(^|\s+)l(\d+)/i );
+		const orderMatch = listStyle.match( /\s*lfo(\d+)/i );
+		const indentMatch = listStyle.match( /\s*level(\d+)/i );
+
+		if ( idMatch && orderMatch && indentMatch ) {
+			data.id = idMatch[ 2 ];
+			data.order = orderMatch[ 1 ];
+			data.indent = indentMatch[ 1 ];
+		}
 	}
 
 	return data;

+ 6 - 3
packages/ckeditor5-paste-from-office/src/filters/space.js

@@ -20,8 +20,8 @@ export function normalizeSpacing( htmlString ) {
 	// Run normalizeSafariSpaceSpans() two times to cover nested spans.
 	return normalizeSafariSpaceSpans( normalizeSafariSpaceSpans( htmlString ) )
 		// Remove all \r\n from "spacerun spans" so the last replace line doesn't strip all whitespaces.
-		.replace( /(<span style=['"]mso-spacerun:yes['"]>[\s]*?)[\r\n]+(\s*<\/span>)/g, '$1$2' )
-		.replace( /<span style=['"]mso-spacerun:yes['"]><\/span>/g, '' )
+		.replace( /(<span\s+style=['"]mso-spacerun:yes['"]>[\s]*?)[\r\n]+(\s*<\/span>)/g, '$1$2' )
+		.replace( /<span\s+style=['"]mso-spacerun:yes['"]><\/span>/g, '' )
 		.replace( / <\//g, '\u00A0</' )
 		.replace( / <o:p><\/o:p>/g, '\u00A0<o:p></o:p>' )
 		// Remove <o:p> block filler from empty paragraph. Safari uses \u00A0 instead of &nbsp;.
@@ -41,7 +41,10 @@ export function normalizeSpacerunSpans( htmlDocument ) {
 	htmlDocument.querySelectorAll( 'span[style*=spacerun]' ).forEach( el => {
 		// Use `el.childNodes[ 0 ].data.length` instead of `el.innerText.length`. For `el.innerText.length` which
 		// contains spaces mixed with `&nbsp;` Edge browser returns incorrect length.
-		const innerTextLength = el.childNodes[ 0 ].data.length;
+		const innerTextLength = ( el.childNodes &&
+			el.childNodes[ 0 ] &&
+			el.childNodes[ 0 ].data &&
+			el.childNodes[ 0 ].data.length ) || 0;
 
 		el.innerHTML = Array( innerTextLength + 1 ).join( '\u00A0 ' ).substr( 0, innerTextLength );
 	} );

+ 11 - 0
packages/ckeditor5-paste-from-office/tests/filters/list.js

@@ -61,6 +61,17 @@ describe( 'PasteFromOffice - filters', () => {
 				expect( stringify( view ) ).to.equal( '<ol><li style="mso-list:">Item 1</li></ol>' );
 			} );
 
+			it( 'handles `mso-list: none` on paragraphs correctly', () => {
+				const html = '<p style="mso-list:none">not numbered<o:p></o:p></p>';
+				const view = htmlDataProcessor.toView( html );
+
+				transformListItemLikeElementsIntoLists( view, '', new View() );
+
+				expect( view.childCount ).to.equal( 1 );
+				expect( view.getChild( 0 ).name ).to.equal( 'ol' );
+				expect( stringify( view ) ).to.equal( '<ol><li style="mso-list:none">not numbered<o:p></o:p></li></ol>' );
+			} );
+
 			it( 'handles empty body correctly', () => {
 				const view = htmlDataProcessor.toView( '' );
 

+ 36 - 0
packages/ckeditor5-paste-from-office/tests/filters/space.js

@@ -81,6 +81,24 @@ describe( 'PasteFromOffice - filters', () => {
 
 				expect( normalizeSpacing( input ) ).to.equal( expected );
 			} );
+
+			// ckeditor5#2095
+			it( 'should detect space spans which are split into multiple lines', () => {
+				const input =
+					'<p><span style=\'font-size:13.0pt;line-height:150%;\n' +
+					'font-family:"Times New Roman",serif\'><span\n' +
+					'style=\'mso-spacerun:yes\'>\n' +
+					'</span><span style=\'mso-spacerun:yes\'>          </span><span\n' +
+					'style=\'mso-spacerun:yes\'>    </span><span style=\'mso-spacerun:yes\'> </span>Test<o:p></o:p></span></p>';
+
+				const expected =
+					'<p><span style=\'font-size:13.0pt;line-height:150%;\nfont-family:"Times New Roman",serif\'>' +
+					'<span style=\'mso-spacerun:yes\'>          </span>' +
+					'<span\nstyle=\'mso-spacerun:yes\'>    </span>' +
+					'<span style=\'mso-spacerun:yes\'> </span>Test<o:p></o:p></span></p>';
+
+				expect( normalizeSpacing( input ) ).to.equal( expected );
+			} );
 		} );
 
 		describe( 'normalizeSpacerunSpans()', () => {
@@ -100,6 +118,24 @@ describe( 'PasteFromOffice - filters', () => {
 
 				expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.equal( expected );
 			} );
+
+			// ckeditor5#5645
+			it( 'should normalize spaces inside special "span.spacerun" elements that contain no data', () => {
+				const input = '<p> <span style=\'mso-spacerun:yes\'>   </span>Foo</p>' +
+					'<p> Baz <span style=\'mso-spacerun:yes\'></span></p>';
+
+				const expected = '<p> <span style="mso-spacerun:yes">&nbsp; &nbsp;</span>Foo</p>' +
+					'<p> Baz <span style="mso-spacerun:yes"></span></p>';
+
+				const domParser = new DOMParser();
+				const htmlDocument = domParser.parseFromString( input, 'text/html' );
+
+				expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.not.equal( expected );
+
+				normalizeSpacerunSpans( htmlDocument );
+
+				expect( htmlDocument.body.innerHTML.replace( /'/g, '"' ).replace( /: /g, ':' ) ).to.equal( expected );
+			} );
 		} );
 	} );
 } );