Skip to content
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

Support for editing Plain text files (like Python, MyST and R Markdown-based) as notebooks #1237

Closed
teonbrooks opened this issue Oct 2, 2020 · 13 comments
Assignees
Labels
*duplicate Issue identified as a duplicate of another issue(s) feature-request Request for new features or functionality notebook-serialization Applies to conversion of ipynb file to JSON & vice versa

Comments

@teonbrooks
Copy link

Recently I've been using jupyter-book as one of my primary notebook environments. It's built on top of MyST, which is a flavor of markdown that is compatible with reStructuredText, and they've built an extension for syntax support.

I really love the integration VSCode has for executing #%% cells in python scripts with and general cells in Jupyter Notebooks. I am wondering if it would be of interest to support other cell paradigms like the ``` code chunk delimiter one in jupyter-book, which is also shared in RMarkdown.
If it's a not feature that fits the roadmap, could you make a suggestion how I might be able to build off what is currently there and support it as an extension?

Thanks a bunch! I really love this product

@rchiodo
Copy link
Contributor

rchiodo commented Oct 2, 2020

This would almost work out of the box. I believe the only changes would be to:

  • Add the .md files to our list of files to provide code lenses for
  • Add a regex to the cell marker regex we have in our settings to recognize python cells (maybe the end of the cell might be a bit more work).

If you wanted to do this in a separate extension, we'd need an extensibility point for submitting code to the python extension (which you could add to our extension with a PR against us too)

@teonbrooks
Copy link
Author

oh awesome. I'm more than happy to have this as a part of this existing extension.

I know that the starting delimiters are:

  • MyST (.md) with all combos:
    • ```{code-block} ipython
    • ```{code-cell} python
  • Rmd (.Rmd):
    • ```{python}

Let me know if there's anything I can do to help

@rchiodo
Copy link
Contributor

rchiodo commented Oct 2, 2020

If you're willing to add a PR, I believe we'd love to accept it. You'd have to expand our code that figures out cell ranges and add those regexes to our searching.

I think after that it would just work. (Might be some things that check for .py - like debugging).

@rchiodo
Copy link
Contributor

rchiodo commented Oct 2, 2020

If you're uncomfortable with a PR, it would likely take a bunch of other people up voting the idea for us to get to it.

@rchiodo
Copy link
Contributor

rchiodo commented Oct 2, 2020

We're happy to help point out where to add changes to our code though.

@teonbrooks
Copy link
Author

@rchiodo, that would be very helpful and i will try to take a stab at it. I was wading through the codebase but some pointers would be welcome

@rchiodo
Copy link
Contributor

rchiodo commented Oct 7, 2020

First I think you'd go here to change the file extensions we provide code lenses for:
https://github.com/microsoft/vscode-python/blob/68aeb2737daa9b86457f1d2df6f3619f7e975aa2/src/client/datascience/datascience.ts#L45

You'd change that PYTHON_ALLFILES to be something else that included your markdown file types.

Then you'd likely change the default regex defined in package.json (and I think in the source too somewhere)
https://github.com/microsoft/vscode-python/blob/68aeb2737daa9b86457f1d2df6f3619f7e975aa2/package.json#L2309

so that it included the patterns you specified above. You'll likely have to add another setting for 'end' cell markers or something

Then finally you'd have to change our logic that finds cell ranges. The crux of that is here:
https://github.com/microsoft/vscode-python/blob/68aeb2737daa9b86457f1d2df6f3619f7e975aa2/src/client/datascience/cellFactory.ts#L153

Right now it assumes the next begin marker is the end of the previous cell. Obviously you'll have to handle the case where your end marker is there too.

Hope that helps. Feel free to submit a draft PR if you want to ask us more questions when you get farther.

@greazer greazer changed the title Support for Markdown-based notebooks Support for MyST and R Markdown-based notebooks Oct 8, 2020
@DonJayamanne DonJayamanne transferred this issue from microsoft/vscode-python Nov 13, 2020
@teonbrooks
Copy link
Author

Hi, unfortunately I don't think I will have time to take this on myself but I think this would be a great improvement to notebook ergonomics in vscode.

@CaseyWeiner
Copy link

If this could happen at some point, that would be really awesome. One idea I had for HTML export is to expand it to prompt the user to pick either a static file or a jupyter book. For example if I choose jupyter book, it opens a GUI prompt to specify traits of the book and then creates the html pages. Could incorporate Github pages with this as well

@greazer greazer added the interactive-window Impacts interactive window label Aug 3, 2021
@greazer greazer added feature-request Request for new features or functionality and removed enhancement labels May 4, 2022
@teonbrooks
Copy link
Author

for visibility, it looks like the quarto vscode extension now supports its version of markdown, qmd (quarto-dev/quarto-cli#149). I think a similar pattern could be used for the code execution part for other markdown files. looks like there's a related PR (#4876) to generalize the markdown within the standard vscode library

@DonJayamanne DonJayamanne added the notebook-serialization Applies to conversion of ipynb file to JSON & vice versa label Aug 15, 2022
@DonJayamanne DonJayamanne self-assigned this Aug 15, 2022
@rebornix rebornix removed the interactive-window Impacts interactive window label Aug 15, 2022
@DonJayamanne DonJayamanne changed the title Support for MyST and R Markdown-based notebooks Support for editing Plain text files (like Python, MyST and R Markdown-based) as notebooks Sep 4, 2022
@arogozhnikov
Copy link

arogozhnikov commented Oct 23, 2022

Moving suggestion from #10174 as recommended by @DonJayamanne

There are a number of already-existing formats that can convert from/to ipynb, implemented as ContentManagers for jupyter. They augment loading/saving process with on-the-fly conversion between filetypes.

While it could be of high value to implement the same for vs code, currently custom NotebookSerializers should provide conversion vscode <> custom format. This requires a lot of logic that is specific to vs code, and requires copying a good chunk of code and dependencies from vs code. (see #10174 and #10121)

Proposal below should simplify support for custom formats by reusing existing converters between ipynb and custom formats.

I suggest that default vscode NotebookSerializer for ipynb could be provided with a following triple:

1. filename extension (e.g. .Rmd, .ipynb.py and others)
2. callback to_ipynb(custom_format_bytes, filepath) -> ipynb_bytes
3. callback from_ipynb(ipynb_bytes, filepath) -> custom_format_bytes

For instance, when saving a file, extension will convert to ipynb, then use a corresponding conversion.

Another possibility is even simpler, in this case work with FS is offloaded to hooks:

1. filename extension (e.g. .Rmd, .ipynb.py and others)
2. callback serialize_from_ipynb(ipynb_bytes, filepath) -> None
3. callback deserialize_to_ipynb(filepath) -> ipynb_bytes

While filepath argument shouldn't be used in most conversions, it will be useful for extensions that grab additional files (like jupytext) or are configured at the repository level so they could have access to configuration files.

Edited on Oct 26: typo and added a link to one more discussion; added an alternative suggestion on hooks

@parmentelat
Copy link

I'd like to +1 here

We have been using (jupytext-powered) text-based notebooks for quite some time now,
because ipynb goes along with git so awkwardly

Using jupyter classic notebook mainly, so together with jupytext
And it would be tremendous help to be able to use vs-code instead

I've been trying to use the vscode-jupytext extension for a while, but this clearly needs more work, so I ended up here following @DonJayamanne's post in that repo

How can we help ?

@DonJayamanne
Copy link
Contributor

Duplicate of #1240

@DonJayamanne DonJayamanne marked this as a duplicate of #1240 Dec 1, 2023
@DonJayamanne DonJayamanne added the *duplicate Issue identified as a duplicate of another issue(s) label Dec 1, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 17, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
*duplicate Issue identified as a duplicate of another issue(s) feature-request Request for new features or functionality notebook-serialization Applies to conversion of ipynb file to JSON & vice versa
Projects
None yet
Development

No branches or pull requests

9 participants