mirror of
https://github.com/zadam/trilium.git
synced 2025-11-07 13:56:11 +01:00
Add autoformat support
This commit is contained in:
38
src/autoformatmath.js
Normal file
38
src/autoformatmath.js
Normal file
@@ -0,0 +1,38 @@
|
||||
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();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user