Commit fb7e3107 authored by Phil Jones's avatar Phil Jones

More advanced proof-of-concept.

Still neads an initial change to any part of the notebook to activate.
parent ad266141
...@@ -12,23 +12,24 @@ declare module 'codemirror' { ...@@ -12,23 +12,24 @@ declare module 'codemirror' {
var modeInfo: any[]; var modeInfo: any[];
} }
CodeMirror.defineMode("finesse", (config) => { CodeMirror.defineMode("finesse-python", (config) => {
let pmode = CodeMirror.getMode(config, "python"); let pmode = CodeMirror.getMode(config, "python");
return CodeMirror.multiplexingMode( return CodeMirror.multiplexingMode(
pmode, pmode,
{ {
open: '#katcode', open: /#katcode/,
close: '"""', close: /(?=""")/, // Match string end without consuming it
mode: CodeMirror.getMode(config, "text/html"), mode: CodeMirror.getMode(config, "text/html"),
delimStyleOpen: "delimit", delimStyle: "delim"
delimStyleClose: "string"
} }
) )
}); });
CodeMirror.defineMIME("text/x-finesse-python", "finesse-python");
Mode.getModeInfo().push({ Mode.getModeInfo().push({
name: 'Finesse', name: 'Finesse Python',
mime: "text/python", mime: "text/x-finesse-python",
mode: 'finesse', mode: 'finesse-python',
ext: [], ext: [],
}); });
import { import {
IDisposable, DisposableDelegate
} from '@phosphor/disposable';
import {
JupyterFrontEnd, JupyterFrontEndPlugin JupyterFrontEnd, JupyterFrontEndPlugin
} from '@jupyterlab/application'; } from '@jupyterlab/application';
import { import {
ToolbarButton NotebookPanel, INotebookTracker, Notebook
} from '@jupyterlab/apputils';
import {
DocumentRegistry
} from '@jupyterlab/docregistry';
import {
NotebookPanel, INotebookModel
} from '@jupyterlab/notebook'; } from '@jupyterlab/notebook';
import { import {
Mode, CodeMirrorEditor CodeCell
} from '@jupyterlab/codemirror' } from '@jupyterlab/cells';
import './codemirror-finesse'; import './codemirror-finesse';
...@@ -30,48 +18,27 @@ import './codemirror-finesse'; ...@@ -30,48 +18,27 @@ import './codemirror-finesse';
*/ */
const plugin: JupyterFrontEndPlugin<void> = { const plugin: JupyterFrontEndPlugin<void> = {
activate, activate,
id: 'my-extension-name:buttonPlugin', id: 'finesse-syntax-jupyter',
requires: [INotebookTracker],
autoStart: true autoStart: true
}; };
function activate(app: JupyterFrontEnd, tracker: INotebookTracker) {
tracker.widgetAdded.connect(activate_finesse)
};
/**
* A notebook widget extension that adds a button to the toolbar.
*/
export
class ButtonExtension implements DocumentRegistry.IWidgetExtension<NotebookPanel, INotebookModel> {
/**
* Create a new extension object.
*/
createNew(panel: NotebookPanel, context: DocumentRegistry.IContext<INotebookModel>): IDisposable {
let callback = () => {
console.log(Mode.getModeInfo());
panel.content.widgets.forEach(cell => {
(cell.editor as CodeMirrorEditor).setOption("mode", "finesse");
});
//NotebookActions.runAll(panel.content, context.session);
};
let button = new ToolbarButton({
className: 'myButton',
iconClassName: 'fa fa-fast-forward',
onClick: callback,
tooltip: 'Run All'
});
panel.toolbar.insertItem(0, 'runAll', button); function check_syntax(sender: Notebook): void {
return new DisposableDelegate(() => { sender.widgets.forEach(cell => {
button.dispose(); if (cell instanceof CodeCell && cell.model.mimeType != "text/x-finesse-python") {
}); cell.model.mimeType = "text/x-finesse-python";
} }
} });
/**
* Activate the extension.
*/
function activate(app: JupyterFrontEnd) {
app.docRegistry.addWidgetExtension('Notebook', new ButtonExtension());
}; };
function activate_finesse(sender: INotebookTracker, panel: NotebookPanel): void {
panel.content.modelContentChanged.connect(check_syntax);
};
/** /**
* Export the plugin as default. * Export the plugin as default.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment