Skip to content

Commit

Permalink
Get extension working
Browse files Browse the repository at this point in the history
  • Loading branch information
hugetim committed Dec 21, 2022
1 parent 99801e1 commit c52183d
Show file tree
Hide file tree
Showing 6 changed files with 9,060 additions and 34 deletions.
25 changes: 19 additions & 6 deletions lib/index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,29 @@
import { stata_mode } from './stata.js';
import { ICodeMirror } from '@jupyterlab/codemirror';

import './stata'

module.exports = [
export default [
{
id: 'jupyterlab_stata_highlight2',
autoStart: true,
activate: function (app) {
requires: [ICodeMirror],
activate: function (app, codeMirror) {
console.log(
'JupyterLab extension jupyterlab_stata_highlight2 is activated!'
'JupyterLab extension jupyterlab_stata_highlight2 is activated-03!'
);
console.log(app.commands);
registerStataFileType(app);
console.log(
'JupyterLab extension jupyterlab_stata_highlight2 end'
);
codeMirror.CodeMirror.defineSimpleMode("stata", stata_mode);
codeMirror.CodeMirror.defineMIME('text/x-stata', 'stata');
codeMirror.CodeMirror.defineMIME('text/stata', 'stata');
codeMirror.CodeMirror.modeInfo.push({
ext: ['do', 'ado'],
mime: "text/x-stata",
mode: 'stata',
name: 'Stata'
});
}
}
];
Expand All @@ -22,4 +35,4 @@ function registerStataFileType(app) {
extensions: ['do', 'ado'],
mimeTypes: ['text/x-stata'],
});
}
}
23 changes: 3 additions & 20 deletions lib/stata.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
// CodeMirror, copyright (c) by Marijn Haverbeke and others
// Distributed under an MIT license: https://codemirror.net/LICENSE
import * as CodeMirror from 'codemirror';
import 'codemirror/addon/mode/simple';

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

// "use strict";

var builtins_base = [
'if', 'else', 'in', 'foreach', 'for', 'forv', 'forva',
'forval', 'forvalu', 'forvalue', 'forvalues', 'by', 'bys',
Expand Down Expand Up @@ -423,8 +419,8 @@ var color_translator = {
};


CodeMirror.defineSimpleMode("stata",{
// The start state contains the rules that are intially used
export const stata_mode = {
// The start state contains the rules that are initially used
start: [
// Comments
{regex: /\/\/\/?.*$/, token: color_translator['comment'], sol: true},
Expand Down Expand Up @@ -496,17 +492,4 @@ CodeMirror.defineSimpleMode("stata",{
lineComment: '//',
fold: 'brace'
}
});

CodeMirror.defineMIME('text/x-stata', 'stata');
CodeMirror.defineMIME('text/stata', 'stata');

// When I paste this file in Jupyter, it won't work unless I include the
// following code, but when I leave this as a separate module, it won't work and
// raises an error.
CodeMirror.modeInfo.push({
ext: ['do', 'ado'],
mime: "text/x-stata",
mode: 'stata',
name: 'Stata'
});
};
14 changes: 7 additions & 7 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"@jupyterlab/codemirror": "*"
},
"devDependencies": {
"@jupyterlab/builder": "^3.0.0",
"@jupyterlab/builder": "^3.5.2",
"rimraf": "^3.0.2"
},
"sideEffects": [
Expand Down
Loading

0 comments on commit c52183d

Please sign in to comment.