Mateusz Samsel 6 lat temu
rodzic
commit
1112165b8f

+ 8 - 8
packages/ckeditor5-paste-from-office/src/normalizer.jsdoc

@@ -8,15 +8,15 @@
  */
 
 /**
- * Normalizer interface is description of a mechanism which transforms input data send through
- * an {@link module:clipboard/clipboard~Clipboard#event:inputTransformation inputTransformation event}. Input content is transformed
- * for data came from office-like applications, for example, : MS Word, Google Docs, etc. These applications generate content,
- * which frequently has an invalid HTML syntax. Normalizers detects environment specific quirks and transform it to proper HTML syntax,
- * what later might be properly upcast to the {@link module:engine/model/model~Model}.
+ * Normalizer interface is a description of a mechanism which transforms input data send through
+ * an {@link module:clipboard/clipboard~Clipboard#event:inputTransformation inputTransformation event}. Input data is transformed
+ * for paste event came from office-like applications, for example, MS Word, Google Docs, etc. These applications generate content,
+ * which frequently has an invalid HTML syntax. Normalizers detects environment-specific quirks and transform it into proper HTML syntax,
+ * what later might be correctly upcast to the {@link module:engine/model/model~Model}.
  *
- * Content Normalizers are registered by {@link module:paste-from-office/pastefromoffice~PasteFromOffice} plugin. Each instance is
- * initialized with an activation trigger. Activation trigger is a function which gets content of `text/html` dataTransfer (String) and
- * returns `true` or `false`. Based on this result normalizer applies filters to given data.
+ * Normalizers are registered by {@link module:paste-from-office/pastefromoffice~PasteFromOffice} plugin. Each instance has the
+ * {@link #isActive} method, which checks if given normalizer should be applied for current data content. It is chosen first active
+ * normalizer for the transformation process. If there is none, then data remain untouched.
  *
  * @interface Normalizer
  */

+ 0 - 37
packages/ckeditor5-paste-from-office/src/normalizer/googledocs.js

@@ -1,37 +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/normalizer
- */
-
-import { removeBoldTagWrapper } from '../filters/common';
-import UpcastWriter from '@ckeditor/ckeditor5-engine/src/view/upcastwriter';
-
-/**
- * Normalizer fixing HTML syntax obtained from Google Docs.
- *
- * @implements module:paste-from-office/normalizer~Normalizer
- */
-export default class GoogleDocsNormalizer {
-	/**
-	 * @inheritDoc
-	 */
-	isActive( htmlString ) {
-		return /id=("|')docs-internal-guid-[-0-9a-f]+("|')/.test( htmlString );
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	exec( data ) {
-		const writer = new UpcastWriter();
-
-		removeBoldTagWrapper( {
-			writer,
-			documentFragment: data.content
-		} );
-	}
-}

+ 0 - 53
packages/ckeditor5-paste-from-office/src/normalizer/msword.js

@@ -1,53 +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/normalizer
- */
-
-import { parseHtml } from '../filters/parse';
-import { transformListItemLikeElementsIntoLists } from '../filters/list';
-import { replaceImagesSourceWithBase64 } from '../filters/image';
-
-/**
- * Normalizer fixing HTML syntax obtained from Microsoft Word documents.
- *
- * @implements module:paste-from-office/normalizer~Normalizer
- */
-export default class MSWordNormalizer {
-	/**
-	 * @inheritDoc
-	 */
-	isActive( htmlString ) {
-		return /<meta\s*name="?generator"?\s*content="?microsoft\s*word\s*\d+"?\/?>/i.test( htmlString ) ||
-				/xmlns:o="urn:schemas-microsoft-com/i.test( htmlString );
-	}
-
-	/**
-	 * @inheritDoc
-	 */
-	exec( data ) {
-		const html = data.dataTransfer.getData( 'text/html' );
-
-		data.content = normalizeWordInput( html, data.dataTransfer );
-	}
-}
-
-//
-// Normalizes input pasted from Word to format suitable for editor {@link module:engine/model/model~Model}.
-//
-// @private
-// @param {String} input Word input.
-// @param {module:clipboard/datatransfer~DataTransfer} dataTransfer Data transfer instance.
-// @returns {module:engine/view/documentfragment~DocumentFragment} Normalized input.
-//
-function normalizeWordInput( input, dataTransfer ) {
-	const { body, stylesString } = parseHtml( input );
-
-	transformListItemLikeElementsIntoLists( body, stylesString );
-	replaceImagesSourceWithBase64( body, dataTransfer.getData( 'text/rtf' ) );
-
-	return body;
-}

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

@@ -21,8 +21,8 @@ import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
  *
  * Transformation is made by a set of predefined {@link module:paste-from-office/normalizer~Normalizer}.
  * Currently, there are included followed normalizers:
- *   * {@link module:paste-from-office/normalizer~MSWordNormalizer MS Word normalizer}
- *   * {@link module:paste-from-office/normalizer~GoogleDocsNormalizer Google Docs normalizer}
+ *   * {@link module:paste-from-office/normalizer/mswordnormalizer~MSWordNormalizer MS Word normalizer}
+ *   * {@link module:paste-from-office/normalizer/googledocsnormalizer~GoogleDocsNormalizer Google Docs normalizer}
  *
  * For more information about this feature check the {@glink api/paste-from-office package page}.
  *