Commit ad266141 authored by Phil Jones's avatar Phil Jones

Initial proof-of-concept.

parents
lib/*
node_modules/*
tsconfig.tsbuildinfo
yarn.lock
# Finesse Syntax for JupyterLab
This diff is collapsed.
{
"name": "finesse-syntax-jupyterlab",
"version": "0.1.0",
"description": "Syntax highlighting for kat script within jupyterlab.",
"keywords": [
"jupyter",
"jupyterlab",
"jupyterlab-extension"
],
"homepage": "https://github.com/my_name/myextension",
"bugs": {
"url": "https://github.com/my_name/myextension/issues"
},
"license": "BSD-3-Clause",
"author": "Phil Jones",
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
"style": "style/index.css",
"repository": {
"type": "git",
"url": "https://github.com/my_name/myextension.git"
},
"scripts": {
"build": "tsc",
"clean": "rimraf lib tsconfig.tsbuildinfo",
"prepare": "jlpm run clean && jlpm run build",
"watch": "tsc -w"
},
"dependencies": {
"@jupyterlab/application": "^1.2.1",
"@jupyterlab/apputils": "^1.2.1",
"@jupyterlab/docregistry": "^1.2.1",
"@jupyterlab/notebook": "^1.2.2",
"@phosphor/disposable": "^1.3.1",
"@phosphor/widgets": "^1.9.3",
"@types/codemirror": "0.0.82",
"codemirror": "5.47.0"
},
"devDependencies": {
"rimraf": "^2.6.1",
"typescript": "~3.5.2"
},
"sideEffects": [
"style/*.css"
],
"jupyterlab": {
"extension": true
}
}
import {
Mode
} from '@jupyterlab/codemirror'
import CodeMirror from 'codemirror';
import 'codemirror/mode/python/python';
import 'codemirror/addon/mode/multiplex';
declare module 'codemirror' {
function multiplexingMode(x: CodeMirror.Mode<any>, ...others: object[]): CodeMirror.Mode<any>;
var modeInfo: any[];
}
CodeMirror.defineMode("finesse", (config) => {
let pmode = CodeMirror.getMode(config, "python");
return CodeMirror.multiplexingMode(
pmode,
{
open: '#katcode',
close: '"""',
mode: CodeMirror.getMode(config, "text/html"),
delimStyleOpen: "delimit",
delimStyleClose: "string"
}
)
});
Mode.getModeInfo().push({
name: 'Finesse',
mime: "text/python",
mode: 'finesse',
ext: [],
});
import {
IDisposable, DisposableDelegate
} from '@phosphor/disposable';
import {
JupyterFrontEnd, JupyterFrontEndPlugin
} from '@jupyterlab/application';
import {
ToolbarButton
} from '@jupyterlab/apputils';
import {
DocumentRegistry
} from '@jupyterlab/docregistry';
import {
NotebookPanel, INotebookModel
} from '@jupyterlab/notebook';
import {
Mode, CodeMirrorEditor
} from '@jupyterlab/codemirror'
import './codemirror-finesse';
/**
* The plugin registration information.
*/
const plugin: JupyterFrontEndPlugin<void> = {
activate,
id: 'my-extension-name:buttonPlugin',
autoStart: true
};
/**
* 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);
return new DisposableDelegate(() => {
button.dispose();
});
}
}
/**
* Activate the extension.
*/
function activate(app: JupyterFrontEnd) {
app.docRegistry.addWidgetExtension('Notebook', new ButtonExtension());
};
/**
* Export the plugin as default.
*/
export default plugin;
{
"compilerOptions": {
"allowSyntheticDefaultImports": true,
"composite": true,
"declaration": true,
"esModuleInterop": true,
"incremental": true,
"jsx": "react",
"module": "esnext",
"moduleResolution": "node",
"noEmitOnError": true,
"noImplicitAny": true,
"noUnusedLocals": true,
"preserveWatchOutput": true,
"resolveJsonModule": true,
"outDir": "lib",
"rootDir": "src",
"strict": true,
"strictNullChecks": false,
"target": "es2017",
"types": []
},
"include": ["src/*"]
}
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