2020-11-07 22:19:00 +02:00
|
|
|
import Plugin from '@ckeditor/ckeditor5-core/src/plugin';
|
|
|
|
import Autoformat from '@ckeditor/ckeditor5-autoformat/src/autoformat';
|
|
|
|
import blockAutoformatEditing from '@ckeditor/ckeditor5-autoformat/src/blockautoformatediting';
|
|
|
|
|
|
|
|
import Math from './math';
|
|
|
|
|
|
|
|
export default class AutoformatMath extends Plugin {
|
|
|
|
static get requires() {
|
|
|
|
return [ Math, Autoformat ];
|
|
|
|
}
|
|
|
|
|
|
|
|
afterInit() {
|
|
|
|
const editor = this.editor;
|
|
|
|
const command = editor.commands.get( 'math' );
|
|
|
|
|
|
|
|
if ( command ) {
|
|
|
|
const mathBlockCallback = getCallbackFunctionForBlockAutoformat( editor, command );
|
|
|
|
|
|
|
|
blockAutoformatEditing( editor, this, /^\\\[$/, mathBlockCallback );
|
|
|
|
blockAutoformatEditing( editor, this, /^\$\$$/, mathBlockCallback );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static get pluginName() {
|
|
|
|
return 'AutoformatMath';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function getCallbackFunctionForBlockAutoformat( editor, command ) {
|
|
|
|
return () => {
|
|
|
|
if ( !command.isEnabled ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
command.display = true;
|
|
|
|
editor.plugins.get( 'MathUI' )._showUI();
|
2021-04-16 17:14:30 -05:00
|
|
|
};
|
2020-11-07 22:19:00 +02:00
|
|
|
}
|