From 5dd666552aad0d7a34c2169f0fd0494fa65f7c61 Mon Sep 17 00:00:00 2001
From: fspreck <f.spreckelsen@indiscale.com>
Date: Tue, 8 Feb 2022 13:11:22 +0100
Subject: [PATCH] WIP: Begin MathJax plugin

---
 src/mathjax_code_delimiters.js | 43 ++++++++++++++++++++++++++++++++++
 1 file changed, 43 insertions(+)
 create mode 100644 src/mathjax_code_delimiters.js

diff --git a/src/mathjax_code_delimiters.js b/src/mathjax_code_delimiters.js
new file mode 100644
index 0000000..4b890c5
--- /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();
+			} );
+		} );
+	}
+}
-- 
GitLab