Procházet zdrojové kódy

Remove generic normalizer.

Mateusz Samsel před 6 roky
rodič
revize
ca51ffaf3b

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

@@ -1,35 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
-
-/**
- * @module paste-from-office/normalizers/genericnormalizer
- */
-
-import { unwrapParagraphInListItem, fixListIndentation } from '../filters/list';
-import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter';
-
-/**
- * Normalizer for the content pasted from different sources, where we can detect wrong syntax.
- *
- * @implements module:paste-from-office/normalizer~Normalizer
- */
-export default class GenericNormalizer {
-	/**
-	 * @inheritDoc
-	 */
-	isActive() {
-		return true;
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	execute( data ) {
-		const writer = new UpcastWriter();
-
-		fixListIndentation( data.content, writer );
-		unwrapParagraphInListItem( data.content, writer );
-	}
-}

+ 4 - 6
packages/ckeditor5-paste-from-office/src/pastefromoffice.js

@@ -12,7 +12,6 @@ import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import GoogleDocsNormalizer from './normalizers/googledocsnormalizer';
 import MSWordNormalizer from './normalizers/mswordnormalizer';
 import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
-import GenericNormalizer from './normalizers/genericnormalizer';
 
 /**
  * The Paste from Office plugin.
@@ -54,9 +53,6 @@ export default class PasteFromOffice extends Plugin {
 		normalizers.push( new MSWordNormalizer() );
 		normalizers.push( new GoogleDocsNormalizer() );
 
-		// GenericNormalizers has to be added as last one, as it always will be activated.
-		normalizers.push( new GenericNormalizer() );
-
 		editor.plugins.get( 'Clipboard' ).on(
 			'inputTransformation',
 			( evt, data ) => {
@@ -67,9 +63,11 @@ export default class PasteFromOffice extends Plugin {
 				const htmlString = data.dataTransfer.getData( 'text/html' );
 				const activeNormalizer = normalizers.find( normalizer => normalizer.isActive( htmlString ) );
 
-				activeNormalizer.execute( data );
+				if ( activeNormalizer ) {
+					activeNormalizer.execute( data );
 
-				data.isTransformedWithPasteFromOffice = true;
+					data.isTransformedWithPasteFromOffice = true;
+				}
 			},
 			{ priority: 'high' }
 		);

+ 0 - 22
packages/ckeditor5-paste-from-office/tests/_data/generic/index.js

@@ -1,22 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
-
-import listInTable from './list-in-table/input.html';
-import listInTableNormalized from './list-in-table/normalized.html';
-import listInTableModel from './list-in-table/model.html';
-
-export const fixtures = {
-	input: {
-		listInTable
-	},
-	normalized: {
-		listInTable: listInTableNormalized
-	},
-	model: {
-		listInTable: listInTableModel
-	}
-};
-
-export const browserFixtures = {};

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 1
packages/ckeditor5-paste-from-office/tests/_data/generic/list-in-table/input.html


Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 1
packages/ckeditor5-paste-from-office/tests/_data/generic/list-in-table/lists-in-table.html


+ 0 - 1
packages/ckeditor5-paste-from-office/tests/_data/generic/list-in-table/model.html

@@ -1 +0,0 @@
-<table><tableRow><tableCell><listItem listIndent="0" listType="bulleted">One</listItem><listItem listIndent="0" listType="bulleted">Two</listItem><listItem listIndent="0" listType="bulleted">Three</listItem></tableCell></tableRow></table>

Rozdílová data souboru nebyla zobrazena, protože soubor je příliš velký
+ 0 - 1
packages/ckeditor5-paste-from-office/tests/_data/generic/list-in-table/normalized.html


+ 2 - 5
packages/ckeditor5-paste-from-office/tests/_utils/fixtures.js

@@ -12,7 +12,6 @@ import { fixtures as spacing, browserFixtures as spacingBrowser } from '../_data
 import { fixtures as googleDocsBoldWrapper, browserFixtures as googleDocsBoldWrapperBrowser }
 	from '../_data/paste-from-google-docs/bold-wrapper/index';
 import { fixtures as googleDocsList, browserFixtures as googleDocsListBrowser } from '../_data/paste-from-google-docs/lists/index.js';
-import { fixtures as listInTable, browserFixtures as listInTableBrowser } from '../_data/generic/index.js';
 
 // Generic fixtures.
 export const fixtures = {
@@ -22,8 +21,7 @@ export const fixtures = {
 	list,
 	spacing,
 	'google-docs-bold-wrapper': googleDocsBoldWrapper,
-	'google-docs-list': googleDocsList,
-	'generic-list-in-table': listInTable
+	'google-docs-list': googleDocsList
 };
 
 // Browser specific fixtures.
@@ -34,6 +32,5 @@ export const browserFixtures = {
 	list: listBrowser,
 	spacing: spacingBrowser,
 	'google-docs-bold-wrapper': googleDocsBoldWrapperBrowser,
-	'google-docs-list': googleDocsListBrowser,
-	'generic-list-in-table': listInTableBrowser
+	'google-docs-list': googleDocsListBrowser
 };

+ 0 - 17
packages/ckeditor5-paste-from-office/tests/normalizers/genericnormalizer.js

@@ -1,17 +0,0 @@
-/**
- * @license Copyright (c) 2003-2019, CKSource - Frederico Knabben. All rights reserved.
- * For licensing, see LICENSE.md or https://ckeditor.com/legal/ckeditor-oss-license
- */
-
-import GenericNormalizer from '../../src/normalizers/genericnormalizer';
-
-// `execute()` of the generic normalizer is tested with autogenerated normalization tests.
-describe( 'GenericNormalizer', () => {
-	const normalizer = new GenericNormalizer();
-
-	describe( 'isActive()', () => {
-		it( 'should return always true ', () => {
-			expect( normalizer.isActive() ).to.be.true;
-		} );
-	} );
-} );

+ 23 - 13
packages/ckeditor5-paste-from-office/tests/pastefromoffice.js

@@ -52,16 +52,36 @@ describe( 'PasteFromOffice', () => {
 			it( 'should process data from google docs', () => {
 				checkCorrectData( '<p id="docs-internal-guid-12345678-1234-1234-1234-1234567890ab"></p>' );
 			} );
+
+			function checkCorrectData( inputString ) {
+				const data = setUpData( inputString );
+				const getDataSpy = sinon.spy( data.dataTransfer, 'getData' );
+
+				clipboard.fire( 'inputTransformation', data );
+
+				expect( data.isTransformedWithPasteFromOffice ).to.be.true;
+				sinon.assert.called( getDataSpy );
+			}
 		} );
 
-		describe( 'data which should be marked with flag by generic normalizer', () => {
+		describe( 'data which should not be marked with flag', () => {
 			it( 'should process data with regular html', () => {
-				checkCorrectData( '<p>Hello world</p>' );
+				checkNotProcessedData( '<p>Hello world</p>' );
 			} );
 
 			it( 'should process data with similar headers to MS Word', () => {
-				checkCorrectData( '<meta name=Generator content="Other">' );
+				checkNotProcessedData( '<meta name=Generator content="Other">' );
 			} );
+
+			function checkNotProcessedData( inputString ) {
+				const data = setUpData( inputString );
+				const getDataSpy = sinon.spy( data.dataTransfer, 'getData' );
+
+				clipboard.fire( 'inputTransformation', data );
+
+				expect( data.isTransformedWithPasteFromOffice ).to.be.undefined;
+				sinon.assert.called( getDataSpy );
+			}
 		} );
 
 		describe( 'data which already have the flag', () => {
@@ -85,16 +105,6 @@ describe( 'PasteFromOffice', () => {
 				sinon.assert.notCalled( getDataSpy );
 			}
 		} );
-
-		function checkCorrectData( inputString ) {
-			const data = setUpData( inputString );
-			const getDataSpy = sinon.spy( data.dataTransfer, 'getData' );
-
-			clipboard.fire( 'inputTransformation', data );
-
-			expect( data.isTransformedWithPasteFromOffice ).to.be.true;
-			sinon.assert.called( getDataSpy );
-		}
 	} );
 
 	// @param {String} inputString html to be processed by paste from office