Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
Fix automath tests
Sauli Anto786fc0f3ce30
diff --git a/package.json b/package.jsonindex 284199b2a0..0d31ab60ee 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.jsindex 9db75022b7..9a9bf6e6ef 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.jsindex cd402e1313..812c6f34e0 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 modelexport function extractDelimiters( equation ) {equation = equation.trim();diff --git a/tests/automath.js b/tests/automath.jsindex a50b369257..b74b028286 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(- '[<mathtex equation="x^2" display="true"></mathtex>]'+ '<paragraph>[<mathtex display="true" equation="x^2" type="script"></mathtex>]</paragraph>');} );@@ -78,7 +79,7 @@ describe( 'AutoMath - integration', () => {clock.tick( 100 );expect( getData( editor.model ) ).to.equal(- '[<mathtex equation="x^2" display="false"></mathtex>]'+ '<paragraph>[<mathtex display="false" equation="x^2" type="script"></mathtex>]</paragraph>');} );@@ -106,7 +107,7 @@ describe( 'AutoMath - integration', () => {clock.tick( 100 );expect( getData( editor.model ) ).to.equal(- '[<mathtex equation="x^2"" display="true"></mathtex>]'+ '<paragraph>[<mathtex display="true" equation="x^2" type="script"></mathtex>]</paragraph>');} );@@ -117,7 +118,7 @@ describe( 'AutoMath - integration', () => {clock.tick( 100 );expect( getData( editor.model ) ).to.equal(- '<paragraph>Fo</paragraph>[<mathtex equation="x^2" display="true"></mathtex>]<paragraph>r</paragraph>'+ '<paragraph>Fo[<mathtex display="true" equation="x^2" type="script"></mathtex>]r</paragraph>');} );@@ -128,22 +129,22 @@ describe( 'AutoMath - integration', () => {clock.tick( 100 );expect( getData( editor.model ) ).to.equal(- '<paragraph>Foo </paragraph>' +- '[<mathtex equation="x^2" display="true"></mathtex>]' +- '<paragraph>Bar</paragraph>'+ '<paragraph>Foo ' ++ '[<mathtex display="true" equation="x^2" type="script"></mathtex>]' ++ 'Bar</paragraph>');} );- it( 'inserts media in-place (non-collapsed selection)', () => {+ it( 'inserts math in-place (non-collapsed selection)', () => {setData( editor.model, '<paragraph>Foo [Bar] Baz</paragraph>' );pasteHtml( editor, '\\[x^2\\]' );clock.tick( 100 );expect( getData( editor.model ) ).to.equal(- '<paragraph>Foo </paragraph>' +- '[<mathtex equation="x^2" display="true"></mathtex>]' +- '<paragraph> Baz</paragraph>'+ '<paragraph>Foo ' ++ '[<mathtex display="true" equation="x^2" type="script"></mathtex>]' ++ ' Baz</paragraph>');} );@@ -154,7 +155,7 @@ describe( 'AutoMath - integration', () => {clock.tick( 100 );expect( getData( editor.model ) ).to.equal(- '\\[x^2\\] \\[\\sqrt{x}2\\]'+ '<paragraph>\\[x^2\\] \\[\\sqrt{x}2\\][]</paragraph>');} );} );