Jelajahi Sumber

Fix handling mso-list:normal. Closes ckeditor/ckeditor5#5712

Ben Demboski 6 tahun lalu
induk
melakukan
21211e4276

+ 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;

+ 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( '' );