diff --git a/package.json b/package.json
index 284199b2a..0d31ab60e 100644
--- a/package.json
+++ b/package.json
@@ -46,7 +46,7 @@
"scripts": {
"lint": "eslint --quiet **/*.js",
"lint:fix": "eslint --quiet **/*.js --fix",
- "test": "node ./node_modules/.bin/ckeditor5-dev-tests"
+ "test": "node node_modules/@ckeditor/ckeditor5-dev-tests/bin/test.js"
},
"lint-staged": {
"**/*.js": [
diff --git a/src/automath.js b/src/automath.js
index 9db75022b..9a9bf6e6e 100644
--- a/src/automath.js
+++ b/src/automath.js
@@ -5,7 +5,7 @@ import LiveRange from '@ckeditor/ckeditor5-engine/src/model/liverange';
import LivePosition from '@ckeditor/ckeditor5-engine/src/model/liveposition';
import global from '@ckeditor/ckeditor5-utils/src/dom/global';
-import { defaultConfig, extractDelimiters, hasDelimiters } from './utils';
+import { defaultConfig, extractDelimiters, hasDelimiters, delimitersCounts } from './utils';
export default class AutoMath extends Plugin {
static get requires() {
@@ -76,7 +76,7 @@ export default class AutoMath extends Plugin {
text = text.trim();
// Skip if don't have delimiters
- if ( !hasDelimiters( text ) ) {
+ if ( !hasDelimiters( text ) || delimitersCounts( text ) !== 2 ) {
return;
}
diff --git a/src/utils.js b/src/utils.js
index cd402e131..812c6f34e 100644
--- a/src/utils.js
+++ b/src/utils.js
@@ -29,6 +29,11 @@ export function hasDelimiters( text ) {
return text.match( /^(\\\[.*?\\\]|\\\(.*?\\\))$/ );
}
+// Find delimiters count
+export function delimitersCounts( text ) {
+ return text.match( /(\\\[|\\\]|\\\(|\\\))/g ).length;
+}
+
// Extract delimiters and figure display mode for the model
export function extractDelimiters( equation ) {
equation = equation.trim();
diff --git a/tests/automath.js b/tests/automath.js
index a50b36925..b74b02828 100644
--- a/tests/automath.js
+++ b/tests/automath.js
@@ -2,6 +2,7 @@ import Mathematics from '../src/math';
import AutoMath from '../src/automath';
import ClassicTestEditor from '@ckeditor/ckeditor5-core/tests/_utils/classictesteditor';
import Clipboard from '@ckeditor/ckeditor5-clipboard/src/clipboard';
+import Paragraph from '@ckeditor/ckeditor5-paragraph/src/paragraph';
import Undo from '@ckeditor/ckeditor5-undo/src/undo';
import Typing from '@ckeditor/ckeditor5-typing/src/typing';
import global from '@ckeditor/ckeditor5-utils/src/dom/global';
@@ -16,7 +17,7 @@ describe( 'AutoMath - integration', () => {
return ClassicTestEditor
.create( editorElement, {
- plugins: [ Mathematics, AutoMath, Typing ]
+ plugins: [ Mathematics, AutoMath, Typing, Paragraph ]
} )
.then( newEditor => {
editor = newEditor;
@@ -63,7 +64,7 @@ describe( 'AutoMath - integration', () => {
clock.tick( 100 );
expect( getData( editor.model ) ).to.equal(
- '[]'
+ '[]'
);
} );
@@ -78,7 +79,7 @@ describe( 'AutoMath - integration', () => {
clock.tick( 100 );
expect( getData( editor.model ) ).to.equal(
- '[]'
+ '[]'
);
} );
@@ -106,7 +107,7 @@ describe( 'AutoMath - integration', () => {
clock.tick( 100 );
expect( getData( editor.model ) ).to.equal(
- '[]'
+ '[]'
);
} );
@@ -117,7 +118,7 @@ describe( 'AutoMath - integration', () => {
clock.tick( 100 );
expect( getData( editor.model ) ).to.equal(
- 'Fo[]r'
+ 'Fo[]r'
);
} );
@@ -128,22 +129,22 @@ describe( 'AutoMath - integration', () => {
clock.tick( 100 );
expect( getData( editor.model ) ).to.equal(
- 'Foo ' +
- '[]' +
- 'Bar'
+ 'Foo ' +
+ '[]' +
+ 'Bar'
);
} );
- it( 'inserts media in-place (non-collapsed selection)', () => {
+ it( 'inserts math in-place (non-collapsed selection)', () => {
setData( editor.model, 'Foo [Bar] Baz' );
pasteHtml( editor, '\\[x^2\\]' );
clock.tick( 100 );
expect( getData( editor.model ) ).to.equal(
- 'Foo ' +
- '[]' +
- ' Baz'
+ 'Foo ' +
+ '[]' +
+ ' Baz'
);
} );
@@ -154,7 +155,7 @@ describe( 'AutoMath - integration', () => {
clock.tick( 100 );
expect( getData( editor.model ) ).to.equal(
- '\\[x^2\\] \\[\\sqrt{x}2\\]'
+ '\\[x^2\\] \\[\\sqrt{x}2\\][]'
);
} );
} );