mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-07-29 11:02:28 +08:00
Fix automath tests
This commit is contained in:
parent
b456ed6965
commit
786fc0f3ce
@ -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": [
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
|
@ -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>'
|
||||
);
|
||||
} );
|
||||
} );
|
||||
|
Loading…
x
Reference in New Issue
Block a user