Explorar o código

Refactor text transformation default transformations.

Maciej Gołaszewski %!s(int64=6) %!d(string=hai) anos
pai
achega
2fb52a652a

+ 26 - 17
packages/ckeditor5-typing/src/texttransformation.js

@@ -10,6 +10,28 @@
 import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
 import TextWatcher from '@ckeditor/ckeditor5-mention/src/textwatcher';
 
+// Set of default transformations provided by the feature.
+const DEFAULT_TRANSFORMATIONS = [
+	// Common symbols:
+	{ from: '\\(c\\)', to: '©' },
+	{ from: '\\(tm\\)', to: '™' },
+
+	// Mathematical:
+	{ from: '1/2', to: '½' },
+	{ from: '<=', to: '≤' },
+
+	// Typography:
+	{ from: '\\.\\.\\.', to: '…' },
+	{ from: ' -- ', to: ' – ' },
+	{ from: ' --- ', to: ' — ' },
+
+	// Quotations:
+	// English primary.
+	{ from: buildQuotesPattern( '"' ), to: '“$1”' },
+	// English secondary.
+	{ from: buildQuotesPattern( '\'' ), to: '‘$1’' }
+];
+
 /**
  * The text transformation plugin.
  *
@@ -25,23 +47,7 @@ export default class TextTransformation extends Plugin {
 		super( editor );
 
 		editor.config.define( 'textTransformation', {
-			transformations: [
-				{ from: '\\(c\\)', to: '©' },
-				{ from: '\\(tm\\)', to: '™' },
-				{ from: '\\.\\.\\.', to: '…' },
-				{ from: '1/2', to: '½' },
-				{ from: '<=', to: '≤' },
-
-				// TODO: not nice - needs special order.
-				// TODO: not nice - needs spaces.
-				{ from: ' --- ', to: ' — ' },
-				{ from: ' -- ', to: ' – ' },
-
-				// English quotation - primary.
-				{ from: buildQuotesPattern( '"' ), to: '“$1”' },
-				// English quotation - secondary.
-				{ from: buildQuotesPattern( '\'' ), to: '‘$1’' }
-			]
+			transformations: DEFAULT_TRANSFORMATIONS
 		} );
 	}
 
@@ -52,6 +58,9 @@ export default class TextTransformation extends Plugin {
 		return 'TextTransformation';
 	}
 
+	/**
+	 * @inheritDoc
+	 */
 	init() {
 		const editor = this.editor;
 		const model = editor.model;

+ 2 - 1
packages/ckeditor5-typing/tests/texttransformation.js

@@ -51,7 +51,8 @@ describe( 'Text transformation feature', () => {
 			testTransformation( '<=', '≤' );
 		} );
 
-		describe( 'dashes', () => {
+		describe( 'typography', () => {
+			testTransformation( '...', '…' );
 			testTransformation( ' -- ', ' – ' );
 			testTransformation( ' --- ', ' — ' );
 		} );