I have a built a package to compile and run C/C++ and FORTRAN sources in a jupyter notebook cell using custom cell magics.
The cell magics are %%CPP %%C and %%FORTRAN.
I can’t seem to get proper syntax highlighting for the cell magics in JupyterLab. This code enables syntax highlighting for ordinary Jupyter notebooks if I put it in ~/.jupyter/custom/custom.js
For dynamic changes of mode depending on cell content, like the use of %%CPP magic, jupyterlab-lsp is one option. Or you could write an extension which re-uses the relevant bits of jupyterlab-lsp. Or we could make it into standalone extension within LSP to let users install it as it seems a common question.
Good suggestions, I’m still not sure how to proceed but it seems that this use case is pretty common and could go into a feature request. All that we need is a way to apply CodeCell’s syntax highlighting for any of its supported languages to any cell magic of our choosing.
Yes, I forgot to mention the LSP path, which is becoming increasingly viable. I’d personally also be happy to help in getting more (open source) language servers packaged on conda-forge, as that’s where we draw our test dependencies (if possible) for jupyter-lsp.
Any news about an easy way to do it? I want support for the iTikZ magic extension: iTikZ GitHub Repository. TikZ is essentially LaTeX images (text/x-stex acorrding to CodeMirror: sTeX mode).
EDITED:
I found an easier solution to add support to highlight a custom magic cell that uses an existing language server in jupyterlab-lsp. The example below extending latex syntax.
Hello, I’m reopening the topic. I use Jupyter notebooks to write Arduino sketches. To do this, I created a magic command %%sketch. To get the correct syntax highlighting, I used the following instructions:
from IPython.core.display import display_javascript
display_javascript("IPython.CodeCell.options_default.highlight_modes['text/x-c++src'] = {'reg':[/^%%sketch/]};", raw=True)
This worked like a charm. Unfortunately, I’ve just updated to the latest version of Jupyter Notebook and it no longer works. If I understand correctly, this change occurred in version 7.
Now, my question is: Is there a simple way (similar to the previous one) to achieve this with the newest versions? I’m a beginner, and I’m just starting to explore JupyterLab, which I’m discovering with this update (I previously only used Jupyter Notebook).
Jupyter Notebook 7+ versions, and going forward, are now built on JupyterLab components. See the second half of my post here for more information with links to resources.
So you have to use JupyterLab-compatible approaches now, which I think means given this thread and the comments to this post the possible options are already covered here.