diff --git a/src/mathjax_code_delimiters.js b/src/mathjax_code_delimiters.js new file mode 100644 index 0000000000000000000000000000000000000000..4b890c58f219540e8d64aa67b55c881e86990f29 --- /dev/null +++ b/src/mathjax_code_delimiters.js @@ -0,0 +1,43 @@ +import { + Plugin +} from 'ckeditor/src/core'; +import { + ButtonView +} from 'ckeditor/src/ui'; + +export default class MathJaxCodeDelimiters extends Plugin { + static get pluginName() { + return 'MathJaxCodeDelimiters'; + } + + init() { + // This is well-defined since this class inherits from `Plugin` + const editor = this.editor; + const model = editor.model; + // Stay compatible to possible future translations + const t = editor.t; + + // Add the inline-math button + editor.ui.componentFactory.add( 'inlineMathButton', locale => { + const view = new ButtonView( locale ); + + view.set( { + label: t( 'Insert inline math delimiters' ), + icon: '$', + tooltip: true, + isToggleable: true + } ); + + // Insert the inline delimiters ("`$$`") into the text at the + // position of the cursor. + this.listenTo( view, 'execute', () => { + model.change( writer => { + const textNode = writer.createText( '`$$`' ); + model.insertContent( textNode ); + } ); + + editor.editing.view.focus(); + } ); + } ); + } +}