Open hugetim opened 1 year ago
You may have already found this, but this discussion thread appears to identify why it stopped working—breaking API changes in the new version of CodeMirror that shipped with JL 4. :(
Right, it should be possible to make it work, but it didn't look like a quick fix when I initially looked into it. So I've just been using JupyterLab 3.x myself, for the time being.
Here are my notes from back then, which I should have posted here:
I got a hack working. It should be possible to implement the changes into an extension, but this hack provides me with something that is working in the meantime:
stata.js
requires changes based on examples from @codemirror/legacy-modes, in particular those that run on simple mode, e.g. Factor. The modified script I use is available here. The file then needs to be put in $CONDA_PREFIX/share/jupyter/lab/staging/node_modules/@codemirror/legacy-modes/mode/
.$CONDA_PREFIX/share/jupyter/lab/staging/node_modules/@jupyterlab/codemirror/src/language.js
and add a new stata mode. Where to put the snippet should be obvious once you open the file:
{
name: 'stata',
displayName: trans.__('Stata'),
mime: 'text/x-stata',
extensions: ['do','ado'],
async load() {
const m = await import('@codemirror/legacy-modes/mode/stata');
return legacy(m.stata);
}
},
jupyter lab build
Thank you for your work on this! I probably won't be able to dig into it myself, to try it out, for several months, but I really appreciate it.
The workaround suggested by @ticoneva doesn't seem to work for me. I may be misreading the instructions, but I made the following changes on my server:
/opt/tljh/user/bin/pip install jupyterlab_stata_highlight2
.stata.js
to /opt/tljh/user/share/jupyter/lab/staging/node_modules/@codemirror/legacy-modes/mode/stata.js
.language.ts
into /opt/tljh/user/share/jupyter/lab/staging/node_modules/@jupyterlab/codemirror/src/language.ts
.I'm pinging @ozak as well since they opened a similar issue.
I also tried it but it didn't work.
I posted the wrong locations in my original instructions. Thanks @arnonerba for pointing that out. I have modified the instructions accordingly.
I would also like to point out that the modification might require---or at least would be a lot easier to apply to---non-minified CodeMirror files, which does not seem to come with some versions of Jupyter Lab. Finally, after the modifications you might need to rebuild Jupyter Lab for this to work:
jupyter lab build
@ticoneva thanks for responding and for updating your original instructions. I've tried jupyter lab build
in my environment, but syntax highlighting still doesn't seem to work. Do you have any other suggestions?
What OS are you using?
It has been a while since I implemented the hack and honestly, I messed around with a lot things, so I cannot confirm with 100% certainty that these steps are all that it takes. I will start fresh on a VM and see if I can provide better instructions.
I'm running TLJH on Ubuntu Server 22.04 LTS with Stata 18.
Thank you for your help!
I'm on MacOS 14.3. Thanks for looking into this!
I have verified that the following steps should work:
conda create -n jupyterlab4 pip nodejs -c conda-forge
conda activate jupyterlab4
conda install jupyterlab -c conda-forge
or
pip install jupyterlab
jupyter lab build --dev-build
wget https://raw.githubusercontent.com/ticoneva/codemirror-legacy-stata/main/stata.js -P $CONDA_PREFIX/share/jupyter/lab/staging/node_modules/@codemirror/legacy-modes/mode/
$CONDA_PREFIX/share/jupyter/lab/staging/node_modules/@jupyterlab/codemirror/lib/language.js
. Search for Squirrel
and add the following entry after that one:
{
name: 'stata',
displayName: trans.__('Stata'),
mime: 'text/x-stata',
extensions: ['do','ado'],
async load() {
const m = await import('@codemirror/legacy-modes/mode/stata');
return legacy(m.stata);
}
},
jupyter lab build
again.
It's not working for me with a new install of JupyterLab 4.0.5.