Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
F
finesse-syntax-jupyterlab
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Philip Jones
finesse-syntax-jupyterlab
Commits
fb7e3107
Commit
fb7e3107
authored
Jan 17, 2020
by
Phil Jones
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
More advanced proof-of-concept.
Still neads an initial change to any part of the notebook to activate.
parent
ad266141
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
26 additions
and
58 deletions
+26
-58
codemirror-finesse.ts
src/codemirror-finesse.ts
+9
-8
index.ts
src/index.ts
+17
-50
No files found.
src/codemirror-finesse.ts
View file @
fb7e3107
...
...
@@ -12,23 +12,24 @@ declare module 'codemirror' {
var
modeInfo
:
any
[];
}
CodeMirror
.
defineMode
(
"finesse"
,
(
config
)
=>
{
CodeMirror
.
defineMode
(
"finesse
-python
"
,
(
config
)
=>
{
let
pmode
=
CodeMirror
.
getMode
(
config
,
"python"
);
return
CodeMirror
.
multiplexingMode
(
pmode
,
{
open
:
'#katcode'
,
close
:
'"""'
,
open
:
/#katcode/
,
close
:
/
(?=
"""
)
/
,
// Match string end without consuming it
mode
:
CodeMirror
.
getMode
(
config
,
"text/html"
),
delimStyleOpen
:
"delimit"
,
delimStyleClose
:
"string"
delimStyle
:
"delim"
}
)
});
CodeMirror
.
defineMIME
(
"text/x-finesse-python"
,
"finesse-python"
);
Mode
.
getModeInfo
().
push
({
name
:
'Finesse'
,
mime
:
"text/python"
,
mode
:
'finesse'
,
name
:
'Finesse
Python
'
,
mime
:
"text/
x-finesse-
python"
,
mode
:
'finesse
-python
'
,
ext
:
[],
});
src/index.ts
View file @
fb7e3107
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
NotebookPanel
,
INotebookTracker
,
Notebook
}
from
'@jupyterlab/notebook'
;
import
{
Mode
,
CodeMirrorEditor
}
from
'@jupyterlab/c
odemirror'
CodeCell
}
from
'@jupyterlab/c
ells'
;
import
'./codemirror-finesse'
;
...
...
@@ -30,48 +18,27 @@ import './codemirror-finesse';
*/
const
plugin
:
JupyterFrontEndPlugin
<
void
>
=
{
activate
,
id
:
'my-extension-name:buttonPlugin'
,
id
:
'finesse-syntax-jupyter'
,
requires
:
[
INotebookTracker
],
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
);
return
new
DisposableDelegate
(()
=>
{
button
.
dispose
();
});
}
}
/**
* Activate the extension.
*/
function
activate
(
app
:
JupyterFrontEnd
)
{
app
.
docRegistry
.
addWidgetExtension
(
'Notebook'
,
new
ButtonExtension
());
function
check_syntax
(
sender
:
Notebook
):
void
{
sender
.
widgets
.
forEach
(
cell
=>
{
if
(
cell
instanceof
CodeCell
&&
cell
.
model
.
mimeType
!=
"text/x-finesse-python"
)
{
cell
.
model
.
mimeType
=
"text/x-finesse-python"
;
}
});
};
function
activate_finesse
(
sender
:
INotebookTracker
,
panel
:
NotebookPanel
):
void
{
panel
.
content
.
modelContentChanged
.
connect
(
check_syntax
);
};
/**
* Export the plugin as default.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment