Преглед изворни кода

Use global RegExp in conversion and test utils.

Maciej Gołaszewski пре 6 година
родитељ
комит
305c8cb6e7

+ 7 - 3
packages/ckeditor5-table/src/tableproperties/tablepropertiesediting.js

@@ -21,6 +21,10 @@ import TableWidthCommand from './commands/tablewidthcommand';
 import TableHeightCommand from './commands/tableheightcommand';
 import TableAlignmentCommand from './commands/tablealignmentcommand';
 
+// RegExp used for matching margin style in converters.
+const MARGIN_REG_EXP = /^(auto|0(%|[a-z]{2,4})?)$/;
+const ALIGN_VALUES_REG_EXP = /^(left|right|center)$/;
+
 /**
  * The table properties editing feature.
  *
@@ -111,8 +115,8 @@ function enableAlignmentProperty( schema, conversion ) {
 		.attributeToAttribute( {
 			view: {
 				styles: {
-					'margin-right': /^(auto|0(%|[a-z]{2,4})?)$/,
-					'margin-left': /^(auto|0(%|[a-z]{2,4})?)$/
+					'margin-right': MARGIN_REG_EXP,
+					'margin-left': MARGIN_REG_EXP
 				}
 			},
 			model: {
@@ -136,7 +140,7 @@ function enableAlignmentProperty( schema, conversion ) {
 		.attributeToAttribute( {
 			view: {
 				attributes: {
-					align: /^(left|right|center)$/
+					align: ALIGN_VALUES_REG_EXP
 				}
 			},
 			model: {

+ 2 - 1
packages/ckeditor5-table/tests/_utils/utils.js

@@ -16,6 +16,7 @@ import { assertEqualMarkup } from '@ckeditor/ckeditor5-utils/tests/_utils/utils'
 import { setData } from '@ckeditor/ckeditor5-engine/src/dev-utils/model';
 
 const WIDGET_TABLE_CELL_CLASS = 'ck-editor__editable ck-editor__nested-editable';
+const BORDER_REG_EXP = /[\s\S]+/;
 
 /**
  * Returns a model representation of a table shorthand notation:
@@ -247,7 +248,7 @@ export function defaultConversion( conversion, asWidget = false ) {
 		view: {
 			name: 'td',
 			styles: {
-				border: /[\s\S]+/
+				border: BORDER_REG_EXP
 			}
 		},
 		model: {