8
0
Просмотр исходного кода

Rename unwrapParagraph and moveNestedLists... function.

Mateusz Samsel 6 лет назад
Родитель
Сommit
771b2d6bb4

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

@@ -238,16 +238,16 @@ function isNewListNeeded( previousItem, currentItem ) {
  * @param {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment} elementOrDocumentFragment
  * @param {module:engine/view/upcastwriter~UpcastWriter} writer
  */
-export function unwrapParagraph( elementOrDocumentFragment, writer ) {
+export function unwrapParagraphInListItem( elementOrDocumentFragment, writer ) {
 	const iterableNodes = elementOrDocumentFragment.is( 'element' ) ? elementOrDocumentFragment.getChildren() : elementOrDocumentFragment;
 
 	for ( const element of iterableNodes ) {
-		if ( element.is( 'element', 'p' ) && element.parent.is( 'element', 'li' ) ) {
+		if ( element.is( 'p' ) && element.parent.is( 'li' ) ) {
 			unwrapSingleElement( element, writer );
 		}
 
 		if ( element.is( 'element' ) && element.childCount ) {
-			unwrapParagraph( element, writer );
+			unwrapParagraphInListItem( element, writer );
 		}
 	}
 }
@@ -258,7 +258,7 @@ export function unwrapParagraph( elementOrDocumentFragment, writer ) {
  * @param {module:engine/view/element~Element|module:engine/view/documentfragment~DocumentFragment} elementOrDocumentFragment
  * @param {module:engine/view/upcastwriter~UpcastWriter} writer
  */
-export function moveNestedListToListItem( elementOrDocumentFragment, writer ) {
+export function fixListIndentation( elementOrDocumentFragment, writer ) {
 	// There are 2 situations which are fixed in the for loop:
 	//
 	// 1. Unwrap nested list to avoid situation that UL or OL is direct child of another UL or OL.
@@ -299,20 +299,20 @@ export function moveNestedListToListItem( elementOrDocumentFragment, writer ) {
 			// 2.
 			const previous = element.previousSibling;
 
-			if ( previous && previous.is( 'element', 'li' ) ) {
+			if ( previous && previous.is( 'li' ) ) {
 				writer.remove( element );
 				writer.insertChild( previous.childCount, element, previous );
 			}
 		}
 
 		if ( element.is( 'element' ) && element.childCount ) {
-			moveNestedListToListItem( element, writer );
+			fixListIndentation( element, writer );
 		}
 	}
 }
 
 function isList( element ) {
-	return element.is( 'element', 'ol' ) || element.is( 'element', 'ul' );
+	return element.is( 'ol' ) || element.is( 'ul' );
 }
 
 function unwrapSingleElement( element, writer ) {

+ 3 - 3
packages/ckeditor5-paste-from-office/src/normalizers/genericnormalizer.js

@@ -7,7 +7,7 @@
  * @module paste-from-office/normalizers/genericnormalizer
  */
 
-import { unwrapParagraph, moveNestedListToListItem } from '../filters/list';
+import { unwrapParagraphInListItem, fixListIndentation } from '../filters/list';
 import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter';
 
 /**
@@ -29,7 +29,7 @@ export default class GenericNormalizer {
 	execute( data ) {
 		const writer = new UpcastWriter();
 
-		moveNestedListToListItem( data.content, writer );
-		unwrapParagraph( data.content, writer );
+		fixListIndentation( data.content, writer );
+		unwrapParagraphInListItem( data.content, writer );
 	}
 }

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

@@ -8,7 +8,7 @@
  */
 
 import removeBoldWrapper from '../filters/removeboldwrapper';
-import { unwrapParagraph, moveNestedListToListItem } from '../filters/list';
+import { unwrapParagraphInListItem, fixListIndentation } from '../filters/list';
 import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter';
 
 const googleDocsMatch = /id=("|')docs-internal-guid-[-0-9a-f]+("|')/i;
@@ -33,7 +33,7 @@ export default class GoogleDocsNormalizer {
 		const writer = new UpcastWriter();
 
 		removeBoldWrapper( data.content, writer );
-		moveNestedListToListItem( data.content, writer );
-		unwrapParagraph( data.content, writer );
+		fixListIndentation( data.content, writer );
+		unwrapParagraphInListItem( data.content, writer );
 	}
 }

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

@@ -10,8 +10,8 @@ import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter';
 
 import {
 	transformListItemLikeElementsIntoLists,
-	unwrapParagraph,
-	moveNestedListToListItem
+	unwrapParagraphInListItem,
+	fixListIndentation
 } from '../../src/filters/list';
 
 describe( 'PasteFromOffice - filters', () => {
@@ -81,12 +81,12 @@ describe( 'PasteFromOffice - filters', () => {
 			writer = new UpcastWriter();
 		} );
 
-		describe( 'unwrapParagraph', () => {
+		describe( 'unwrapParagraphInListItem', () => {
 			it( 'should remove paragraph from list item remaining nested elements', () => {
 				const inputData = '<ul><li><p>foo</p></li><li><p><span>bar</span></p></li></ul>';
 				const documentFragment = htmlDataProcessor.toView( inputData );
 
-				unwrapParagraph( documentFragment, writer );
+				unwrapParagraphInListItem( documentFragment, writer );
 
 				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal(
 					'<ul><li>foo</li><li><span>bar</span></li></ul>'
@@ -111,7 +111,7 @@ describe( 'PasteFromOffice - filters', () => {
 					'</ul>';
 				const documentFragment = htmlDataProcessor.toView( inputData );
 
-				unwrapParagraph( documentFragment, writer );
+				unwrapParagraphInListItem( documentFragment, writer );
 
 				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal(
 					'<ul><li>one<ol><li>two<ul><li>three</li></ul></li></ol></li></ul>'
@@ -119,7 +119,7 @@ describe( 'PasteFromOffice - filters', () => {
 			} );
 		} );
 
-		describe( 'moveNestedListToListItem', () => {
+		describe( 'fixListIndentation', () => {
 			it( 'should move nested list to previous list item', () => {
 				const inputData = '<ul>' +
 						'<li>one</li>' +
@@ -132,7 +132,7 @@ describe( 'PasteFromOffice - filters', () => {
 
 				const documentFragment = htmlDataProcessor.toView( inputData );
 
-				moveNestedListToListItem( documentFragment, writer );
+				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>'
@@ -145,7 +145,7 @@ describe( 'PasteFromOffice - filters', () => {
 				const inputData = '<ul><li>foo</li><ul><ul><ul><ul><li>bar</li></ul></ul></ul></ul></ul>';
 				const documentFragment = htmlDataProcessor.toView( inputData );
 
-				moveNestedListToListItem( documentFragment, writer );
+				fixListIndentation( documentFragment, writer );
 
 				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal(
 					'<ul><li>foo<ul><li>bar</li></ul></li></ul>'
@@ -185,7 +185,7 @@ describe( 'PasteFromOffice - filters', () => {
 
 				const documentFragment = htmlDataProcessor.toView( inputData );
 
-				moveNestedListToListItem( documentFragment, writer );
+				fixListIndentation( documentFragment, writer );
 
 				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal(
 					'<ol>' +
@@ -226,7 +226,7 @@ describe( 'PasteFromOffice - filters', () => {
 					'</ol>';
 				const documentFragment = htmlDataProcessor.toView( inputData );
 
-				moveNestedListToListItem( documentFragment, writer );
+				fixListIndentation( documentFragment, writer );
 
 				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( '<ol><li>foo</li></ol>' );
 			} );
@@ -240,7 +240,7 @@ describe( 'PasteFromOffice - filters', () => {
 					'</ul>';
 				const documentFragment = htmlDataProcessor.toView( inputData );
 
-				moveNestedListToListItem( documentFragment, writer );
+				fixListIndentation( documentFragment, writer );
 
 				expect( htmlDataProcessor.toData( documentFragment ) ).to.equal( '<ol><li>foo</li></ol><ul><li>bar</li></ul>' );
 			} );