Closed adamjstewart closed 2 years ago
The code highlighting is done with pygments
, and the information about the language is taken from the cell metadata magics_language
. If that's not present (as in your case), the notebook metadata language_info.pygments_lexer
is checked. If that's not present (as in your case), language_info.name
is used, which in your case is python
, so it doesn't know the special IPython syntax.
In general, you could override it with nbsphinx_codecell_lexer
but language_info.name
seems to take precedence. Maybe that should be changed?
BTW, if you just want to ignore the warning, you can use that in your conf.py
:
suppress_warnings = ['misc.highlighting_failure']
Yes, I ignored the warning for now. What's the correct value for magics_language, ipython?
Is there any downside to using ipython as the lexer for all .ipynb
files? I'm surprised the default is python instead of ipython.
Yep, that seems to work. Thanks for all of your help!
What's the correct value for magics_language, ipython?
I don't know.
I've never knowingly seen a notebook where this was set.
I don't know if there is any client that writes to that field.
I don't know why I originally implemented it that way (see #59 and #60, which was 6 years ago!), maybe I copied it from nbconvert
?
But both ipython
and ipython3
should work.
Is there any downside to using ipython as the lexer for all
.ipynb
files?
I'm not sure.
The idea is that Jupyter notebooks are language-agnostic, so I would prefer not assuming IPython.
I'm surprised the default is python instead of ipython.
Well, none of those are explicitly the default, but nb.metadata.language_info.name
seems to be python
.
But that may not be a good idea, because, as we saw, this cannot handle IPython-specific features.
So we might just remove this? This would lead to no highlighting instead of raising an error.
In such a case, a user could override the language with nbsphinx_codecell_lexer
.
Does that make sense?
A warning and highlighting is definitely better than no warning and no highlighting.
I have a cell block containing a shell command:
This runs and renders fine on Google Colab. However, when I build my docs with nbsphinx, I see the following warning message:
This seems to work for nbsphinx, but not for Jupyter:
This seems to work for Jupyter, but not for nbsphinx:
See https://readthedocs.org/projects/torchgeo/builds/17978930/ for the failing build and see https://github.com/microsoft/torchgeo/pull/756 for links to the full notebook. This is with nbsphinx 0.8.9.