Skip to content

Commit c52183d

Browse files
committed
Get extension working
1 parent 99801e1 commit c52183d

File tree

6 files changed

+9060
-34
lines changed

6 files changed

+9060
-34
lines changed

lib/index.js

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,29 @@
1+
import { stata_mode } from './stata.js';
2+
import { ICodeMirror } from '@jupyterlab/codemirror';
13

2-
import './stata'
3-
4-
module.exports = [
4+
export default [
55
{
66
id: 'jupyterlab_stata_highlight2',
77
autoStart: true,
8-
activate: function (app) {
8+
requires: [ICodeMirror],
9+
activate: function (app, codeMirror) {
910
console.log(
10-
'JupyterLab extension jupyterlab_stata_highlight2 is activated!'
11+
'JupyterLab extension jupyterlab_stata_highlight2 is activated-03!'
1112
);
1213
console.log(app.commands);
1314
registerStataFileType(app);
15+
console.log(
16+
'JupyterLab extension jupyterlab_stata_highlight2 end'
17+
);
18+
codeMirror.CodeMirror.defineSimpleMode("stata", stata_mode);
19+
codeMirror.CodeMirror.defineMIME('text/x-stata', 'stata');
20+
codeMirror.CodeMirror.defineMIME('text/stata', 'stata');
21+
codeMirror.CodeMirror.modeInfo.push({
22+
ext: ['do', 'ado'],
23+
mime: "text/x-stata",
24+
mode: 'stata',
25+
name: 'Stata'
26+
});
1427
}
1528
}
1629
];
@@ -22,4 +35,4 @@ function registerStataFileType(app) {
2235
extensions: ['do', 'ado'],
2336
mimeTypes: ['text/x-stata'],
2437
});
25-
}
38+
}

lib/stata.js

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,9 @@
11
// CodeMirror, copyright (c) by Marijn Haverbeke and others
22
// Distributed under an MIT license: https://codemirror.net/LICENSE
3-
import * as CodeMirror from 'codemirror';
4-
import 'codemirror/addon/mode/simple';
53

64
// Code below adapted from jupyterlab-stata-highlight, copyright (c) by Kyle Barron
75
// Distributed under an MIT license: https://github.com/kylebarron/jupyterlab-stata-highlight/blob/master/LICENSE
86

9-
// "use strict";
10-
117
var builtins_base = [
128
'if', 'else', 'in', 'foreach', 'for', 'forv', 'forva',
139
'forval', 'forvalu', 'forvalue', 'forvalues', 'by', 'bys',
@@ -423,8 +419,8 @@ var color_translator = {
423419
};
424420

425421

426-
CodeMirror.defineSimpleMode("stata",{
427-
// The start state contains the rules that are intially used
422+
export const stata_mode = {
423+
// The start state contains the rules that are initially used
428424
start: [
429425
// Comments
430426
{regex: /\/\/\/?.*$/, token: color_translator['comment'], sol: true},
@@ -496,17 +492,4 @@ CodeMirror.defineSimpleMode("stata",{
496492
lineComment: '//',
497493
fold: 'brace'
498494
}
499-
});
500-
501-
CodeMirror.defineMIME('text/x-stata', 'stata');
502-
CodeMirror.defineMIME('text/stata', 'stata');
503-
504-
// When I paste this file in Jupyter, it won't work unless I include the
505-
// following code, but when I leave this as a separate module, it won't work and
506-
// raises an error.
507-
CodeMirror.modeInfo.push({
508-
ext: ['do', 'ado'],
509-
mime: "text/x-stata",
510-
mode: 'stata',
511-
name: 'Stata'
512-
});
495+
};

package-lock.json

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
"@jupyterlab/codemirror": "*"
4242
},
4343
"devDependencies": {
44-
"@jupyterlab/builder": "^3.0.0",
44+
"@jupyterlab/builder": "^3.5.2",
4545
"rimraf": "^3.0.2"
4646
},
4747
"sideEffects": [

0 commit comments

Comments
 (0)