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' {
...
@@ -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
:
[],
});
});
src/index.ts
View file @
fb7e3107
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/c
odemirror'
}
from
'@jupyterlab/c
ells'
;
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
);
return
new
DisposableDelegate
(()
=>
{
button
.
dispose
();
});
}
}
/**
function
check_syntax
(
sender
:
Notebook
):
void
{
* Activate the extension.
sender
.
widgets
.
forEach
(
cell
=>
{
*/
if
(
cell
instanceof
CodeCell
&&
cell
.
model
.
mimeType
!=
"text/x-finesse-python"
)
{
function
activate
(
app
:
JupyterFrontEnd
)
{
cell
.
model
.
mimeType
=
"text/x-finesse-python"
;
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.
...
...
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