Sfoglia il codice sorgente

Merge pull request #80 from ckeditor/t/ckeditor5-list/115

Other: Remove the `fixListIndentation()` filter in favor of improved list converters fix. See ckeditor/ckeditor5-list#115.
Piotrek Koszuliński 6 anni fa
parent
commit
ab846bf16b

+ 0 - 59
packages/ckeditor5-paste-from-office/src/filters/list.js

@@ -70,65 +70,6 @@ export function unwrapParagraphInListItem( documentFragment, writer ) {
 	}
 }
 
-/**
- * Fix structure of nested lists to follow HTML guidelines and normalize content in predictable way.
- *
- * 1. Move nested lists to have sure that list items are the only children of lists.
- *
- *		before:                           after:
- *		OL                                OL
- *		|-> LI                            |-> LI
- *		|-> OL                                |-> OL
- *		    |-> LI                                |-> LI
- *
- * 2. Remove additional indentation which cannot be recreated in HTML structure.
- *
- *		before:                           after:
- *		OL                                OL
- *		|-> LI                            |-> LI
- *		    |-> OL                            |-> OL
- *		        |-> OL                            |-> LI
- *		        |   |-> OL                        |-> LI
- *		        |       |-> OL
- *		        |           |-> LI
- *		        |-> LI
- *
- *		before:                           after:
- *		OL                                OL
- *		|-> OL                             |-> LI
- *		    |-> OL
- *		         |-> OL
- *		             |-> LI
- *
- * @param {module:engine/view/documentfragment~DocumentFragment} documentFragment
- * @param {module:engine/view/upcastwriter~UpcastWriter} writer
- */
-export function fixListIndentation( documentFragment, writer ) {
-	for ( const value of writer.createRangeIn( documentFragment ) ) {
-		const element = value.item;
-
-		// case 1: The previous sibling of a list is a list item.
-		if ( element.is( 'li' ) ) {
-			const next = element.nextSibling;
-
-			if ( next && isList( next ) ) {
-				writer.remove( next );
-				writer.insertChild( element.childCount, next, element );
-			}
-		}
-
-		// case 2: The list is the first child of another list.
-		if ( isList( element ) ) {
-			let firstChild = element.getChild( 0 );
-
-			while ( isList( firstChild ) ) {
-				writer.unwrapElement( firstChild );
-				firstChild = element.getChild( 0 );
-			}
-		}
-	}
-}
-
 // Finds all list-like elements in a given document fragment.
 //
 // @param {module:engine/view/documentfragment~DocumentFragment} documentFragment Document fragment

+ 0 - 1
packages/ckeditor5-paste-from-office/src/normalizers/googledocsnormalizer.js

@@ -33,7 +33,6 @@ export default class GoogleDocsNormalizer {
 		const writer = new UpcastWriter();
 
 		removeBoldWrapper( data.content, writer );
-		fixListIndentation( data.content, writer );
 		unwrapParagraphInListItem( data.content, writer );
 	}
 }

+ 0 - 10
packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/index.js

@@ -4,19 +4,15 @@
  */
 
 import nestedOrderedList from './nested-ordered-lists/input.html';
-import nestedOrderedListNormalized from './nested-ordered-lists/normalized.html';
 import nestedOrderedListModel from './nested-ordered-lists/model.html';
 
 import mixedList from './mixed-list/input.html';
-import mixedListNormalized from './mixed-list/normalized.html';
 import mixedListModel from './mixed-list/model.html';
 
 import repeatedlyNestedList from './repeatedly-nested-list/input.html';
-import repeatedlyNestedListNormalized from './repeatedly-nested-list/normalized.html';
 import repeatedlyNestedListModel from './repeatedly-nested-list/model.html';
 
 import partiallySelected from './partially-selected/input.html';
-import partiallySelectedNormalized from './partially-selected/normalized.html';
 import partiallySelectedModel from './partially-selected/model.html';
 
 export const fixtures = {
@@ -26,12 +22,6 @@ export const fixtures = {
 		repeatedlyNestedList,
 		partiallySelected
 	},
-	normalized: {
-		nestedOrderedList: nestedOrderedListNormalized,
-		mixedList: mixedListNormalized,
-		repeatedlyNestedList: repeatedlyNestedListNormalized,
-		partiallySelected: partiallySelectedNormalized
-	},
 	model: {
 		nestedOrderedList: nestedOrderedListModel,
 		mixedList: mixedListModel,

File diff suppressed because it is too large
+ 0 - 0
packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/mixed-list/normalized.html


File diff suppressed because it is too large
+ 0 - 0
packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/nested-ordered-lists/normalized.html


File diff suppressed because it is too large
+ 0 - 0
packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/partially-selected/normalized.html


File diff suppressed because it is too large
+ 0 - 0
packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/repeatedly-nested-list/normalized.html


+ 0 - 7
packages/ckeditor5-paste-from-office/tests/_data/paste-from-google-docs/lists/repeatedly-nested-list/repeatedly-nested-list.html

@@ -58,13 +58,6 @@ describe( 'PasteFromOffice - normalization', () => {
 		editorConfig
 	} );
 
-	generateTests( {
-		input: 'google-docs-list',
-		type: 'normalization',
-		browsers,
-		editorConfig
-	} );
-
 	generateTests( {
 		input: 'generic-list-in-table',
 		type: 'normalization',

+ 1 - 129
packages/ckeditor5-paste-from-office/tests/filters/list.js

@@ -10,8 +10,7 @@ import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter';
 
 import {
 	transformListItemLikeElementsIntoLists,
-	unwrapParagraphInListItem,
-	fixListIndentation
+	unwrapParagraphInListItem
 } from '../../src/filters/list';
 
 describe( 'PasteFromOffice - filters', () => {
@@ -127,132 +126,5 @@ describe( 'PasteFromOffice - filters', () => {
 				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( '<ol><li>foo</li><li>bar<ul><li>baz</li></ul></li></ol>' );
 			} );
 		} );
-
-		describe( 'fixListIndentation', () => {
-			it( 'should move nested list to previous list item', () => {
-				const inputData = '<ul>' +
-						'<li>one</li>' +
-						'<ul>' +
-							'<li>two</li>' +
-							'<li>three</li>' +
-						'</ul>' +
-						'<li>four</li>' +
-					'</ul>';
-
-				const documentFragment = htmlDataProcessor.toView( inputData );
-
-				fixListIndentation( documentFragment, writer );
-
-				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal(
-					'<ul><li>one<ul><li>two</li><li>three</li></ul></li><li>four</li></ul>'
-				);
-			} );
-		} );
-
-		describe( 'repeatedly nested lists are normalized', () => {
-			it( 'should unwrap single nested list', () => {
-				const inputData = '<ul><li>foo</li><ul><ul><ul><ul><li>bar</li></ul></ul></ul></ul></ul>';
-				const documentFragment = htmlDataProcessor.toView( inputData );
-
-				fixListIndentation( documentFragment, writer );
-
-				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal(
-					'<ul><li>foo<ul><li>bar</li></ul></li></ul>'
-				);
-			} );
-
-			it( 'should preserve sibling elements in correct relation', () => {
-				const inputData = '<ol>' +
-						'<li>foo</li>' +
-						'<ol>' +
-							'<ol>' +
-								'<ol>' +
-									'<li>one</li>' +
-								'</ol>' +
-								'<li>two</li>' +
-							'</ol>' +
-							'<li>three</li>' +
-							'<ol>' +
-								'<ol>' +
-									'<ol>' +
-										'<li>four</li>' +
-									'</ol>' +
-								'</ol>' +
-							'</ol>' +
-						'</ol>' +
-						'<li>correct' +
-							'<ol>' +
-								'<li>AAA' +
-									'<ol>' +
-										'<li>BBB</li>' +
-										'<li>CCC</li>' +
-									'</ol>' +
-								'</li>' +
-							'</ol>' +
-						'</li>' +
-					'</ol>';
-
-				const documentFragment = htmlDataProcessor.toView( inputData );
-
-				fixListIndentation( documentFragment, writer );
-
-				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal(
-					'<ol>' +
-						'<li>foo' +
-							'<ol>' +
-								'<li>one</li>' +
-								'<li>two</li>' +
-								'<li>three' +
-										'<ol>' +
-											'<li>four</li>' +
-										'</ol>' +
-								'</li>' +
-							'</ol>' +
-						'</li>' +
-						'<li>correct' +
-							'<ol>' +
-								'<li>AAA' +
-									'<ol>' +
-										'<li>BBB</li>' +
-										'<li>CCC</li>' +
-									'</ol>' +
-								'</li>' +
-							'</ol>' +
-						'</li>' +
-					'</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 );
-
-				fixListIndentation( documentFragment, writer );
-
-				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( '<ol><li>foo</li></ol>' );
-			} );
-
-			it( 'should normalize 2 sibling list independently', () => {
-				const inputData = '<ol>' +
-						'<li>foo</li>' +
-					'</ol>' +
-					'<ul>' +
-						'<li>bar</li>' +
-					'</ul>';
-				const documentFragment = htmlDataProcessor.toView( inputData );
-
-				fixListIndentation( documentFragment, writer );
-
-				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( '<ol><li>foo</li></ol><ul><li>bar</li></ul>' );
-			} );
-		} );
 	} );
 } );

Some files were not shown because too many files changed in this diff