Sfoglia il codice sorgente

Fix sibling lists.

Mateusz Samsel 6 anni fa
parent
commit
81d4496106

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

@@ -74,7 +74,7 @@ export function moveNestedListToListItem( elementOrDocumentFragment, writer ) {
 			// 2.
 			// 2.
 			const previous = element.previousSibling;
 			const previous = element.previousSibling;
 
 
-			if ( previous ) {
+			if ( previous && previous.is( 'element', 'li' ) ) {
 				writer.remove( element );
 				writer.remove( element );
 				writer.insertChild( previous.childCount, element, previous );
 				writer.insertChild( previous.childCount, element, previous );
 			}
 			}

+ 17 - 0
packages/ckeditor5-paste-from-office/tests/filters/common.js

@@ -151,6 +151,23 @@ describe( 'PasteFromOffice/filters', () => {
 					'</ol>'
 					'</ol>'
 				);
 				);
 			} );
 			} );
+
+			it( 'should normalize lists which are start from nested elements', () => {
+				const inputData = '<ol>' +
+						'<ol>' +
+							'<ol>' +
+								'<ol>' +
+									'<li>foo</li>' +
+								'</ol>' +
+							'</ol>' +
+						'</ol>' +
+					'</ol>';
+				const documentFragment = htmlDataProcessor.toView( inputData );
+
+				moveNestedListToListItem( documentFragment, writer );
+
+				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( '<ol><li>foo</li></ol>' );
+			} );
 		} );
 		} );
 	} );
 	} );
 } );
 } );