-
Notifications
You must be signed in to change notification settings - Fork 388
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Losing code cell language from MyST markdown inputs with --pipe black
#1267
Comments
Hi @davidorme , thank you for reporting this! We would need to make sure that this language information is preserved when the notebook is converted to a Jupyter notebook (the Let me check with @chrisjsewell who knows that part better than I do, what happens to that language specification when the conversion occurs. |
Will put it on the todo list to have a look 😅 but feel free to ping me again if I don't reply |
@chrisjsewell Sorry to ping you on this. I've got It's not a huge deal - we're just only committing files stripped of |
Oh actually I realize that this is an issue that has been going on for a very long time! See #759, #778, #789. What happens is that the language specification on the code cell comes from the That information is in the notebook when you save it from Jupyter, but it is lost when you read the MyST file. I see one immediate workaround: add the
On the longer term, I see two possible fixes:
My preference goes to 1 but I am curious to hear yours @chrisjsewell @davidorme @parmentelat |
I may have got this wrong but I have [tool.jupytext]
# Stop jupytext from removing mystnb and other settings in MyST Notebook YAML headers
notebook_metadata_filter = """
settings,
mystnb,
language_info
""" And then a markdown file with YAML headers: ---
jupytext:
text_representation:
extension: .md
format_name: myst
format_version: 0.13
jupytext_version: 1.16.4
kernelspec:
display_name: Python 3 (ipykernel)
language: python
name: python3
--- If I run
But all of the |
I see! You still don't have a |
Alright. That took longer than expected:
But. With the config above committed and language_info:
codemirror_mode:
name: ipython
version: 3
file_extension: .py
mimetype: text/x-python
name: python
nbconvert_exporter: python
pygments_lexer: ipython3
version: 3.11.9 Saving in
I don't understand the boundaries between the different packages at all well, but if I understand correctly:
I'm not sure what (1) adds beyond the workaround - does it mean that |
I think I've run into a workflow that - if I understand correctly - argues for option (2). This usage might be out of scope for The workflow is in creating Myst markdown notebooks for rendering using
That feels clunky. I get that |
We're using
jupytext --pipe black
to automatically format Python code in MyST markdown notebooks (as part of pre-commit, but I don't think that's relevant here). The problem we're having is that (IIUC) the round trip through the percent format to pass it toblack
strips out the language specification on thecode-cell
directives. So given:Running that through
jupytext --pipe black
results in:That does affect other tools that rely on the language specification for syntax highlighting of code cells - we're using VSCode. I wondered if this might be tackled by setting
cell_metadata_filter = "all"
but I think that language specification is not part of the cell metadata? I don't think that any of the other settings in config.py tackle this?The text was updated successfully, but these errors were encountered: