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

Open linked .md files as notebooks in Jupyter Lab #271

Closed
mwouts opened this issue Jun 30, 2019 · 21 comments · Fixed by #889 or #891
Closed

Open linked .md files as notebooks in Jupyter Lab #271

mwouts opened this issue Jun 30, 2019 · 21 comments · Fixed by #889 or #891
Milestone

Comments

@mwouts
Copy link
Owner

mwouts commented Jun 30, 2019

At #263 we converted all the notebooks from the Python Data Science Handbooks to their Jupytext Markdown representation, with a .md extension. These files can still be opened as notebooks in Jupyter Lab, and the user can run them.

However, if we follow the links to the other notebooks, these links open as Markdown files. Opening them as notebooks would be more convenient in this context.

Maybe all text files with a YAML header should open as a notebook by default? @jasongrout, @grst, what do you think?

@mwouts
Copy link
Owner Author

mwouts commented Jun 30, 2019

Recall that the Open as notebook menu was added at jupyterlab/jupyterlab#5247

@mwouts
Copy link
Owner Author

mwouts commented Jun 30, 2019

@choldgraf , @betatim, I have a related question regarding mybinder: is it possible to state in the URL that I want to open a specific .md file with the notebook editor in JupyterLab? What would be that URL for https://mybinder.org/v2/gh/mwouts/PythonDataScienceHandbook/jupytext_no_ipynb?filepath=notebooks/Index.md ?

@grst
Copy link
Contributor

grst commented Jun 30, 2019

Maybe all text files with a YAML header should open as a notebook by default? @jasongrout, @grst, what do you think?

Ideally, this could be handled by the Jupytext extension. In that case no Jupyterlab core code would have to be altered and additionally, it could be a Jupytext configurable.

Though, I'm not familiar enough with jupyterlab to know if it is feasible for an extension to manipulate the way a file is handled. Maybe @jasongrout can comment on this.

@choldgraf
Copy link
Contributor

choldgraf commented Jun 30, 2019

@mwouts yep - instead of filepath=, you should use urlpath=lab/tree/path/to/file.md

@mwouts
Copy link
Owner Author

mwouts commented Jul 2, 2019

Ideally, this could be handled by the Jupytext extension

I agree. I think that I'd like to add more notebook types in the registry. And probably add them before the non-notebook types... But I have no idea if an extension can do that...

@choldgraf , my question was related to the 'widget' that is used to open the file. When I go to https://mybinder.org/v2/gh/mwouts/PythonDataScienceHandbook/jupytext_no_ipynb?urlpath=lab/tree/notebooks/Index.md it uses the 'Editor' widget. I would like to tell Jupyter Lab to use the 'Notebook' widget. But I see that already with a local Jupyter Lab I don't know how to do that from the url...

@choldgraf
Copy link
Contributor

ah good question - that one is beyond my knowledge of JupyterLab, I'm not much of an expert there :-/

@mwouts
Copy link
Owner Author

mwouts commented Jan 12, 2020

@jasongrout, I am giving a try to the user settings in Jupyter Lab, they really seem to be what I am looking for - but unfortunately I don't see what they change in practise.

For instance, in the experience below, I set the user settings to this:

{
    defaultViewers: {
        markdown: "Editor"
    }
}

With that, I would have expected that clicking on a link to another md file would open that file in the Editor, rather than in the Markdown Previewer. But the opposite happens. Do you have an idea of what I got wrong? Thanks!
test_md_viewer

@jasongrout
Copy link

I just checked as well, and indeed in 1.2.4, at least, that setting will control what happens when you double-click on the file (try changing it to "markdown preview" and double-clicking on a markdown file in the file browser). However it seems to not be used when clicking on a link to open a file. This looks like a bug to me. CC @ian-r-rose, who (IIRC) wrote that defaultViewer override functionality.

@jasongrout
Copy link

I tracked down the problem and opened an issue: jupyterlab/jupyterlab#7776

@mwouts
Copy link
Owner Author

mwouts commented Jan 13, 2020

Awesome. Thank you so much @jasongrout

@choldgraf
Copy link
Contributor

Hey all - did this issue get resolved? I am working on building in more Jupytext integrations in Jupyter Book, and I'd like to be able to create Binder links that automatically open the file as a notebook rather than a markdown file. @mwouts any chance this is possible yet?

@mwouts
Copy link
Owner Author

mwouts commented Apr 10, 2020

Hello @choldgraf , I am not aware of any progress here, sorry. Furthermore, I am not very familiar with TypeScript yet, and this makes it a bit harder for me to work on this kind of issue...

As discussed above, I think there are two possible approaches: either we try and see how to fix the viewer settings at jupyterlab/jupyterlab#7776, or we find a way to do that in the Jupytext extension for JupyterLab.

@choldgraf
Copy link
Contributor

Makes sense - in the meantime I will try and get around this with some documentation in the new jupyter book docs (beta.jupyterbook.org)...I don't think it will be too clunky for folks, especially if they're willing to have both an ipynb and a md file in their repo

@astrojuanlu
Copy link

It also happens with other extensions, like .mystnb. It's not clear to me whether the defaultViewers configuration introduced in jupyterlab/jupyterlab#6813 helps with this.

@akhmerov
Copy link

akhmerov commented Aug 7, 2021

Is

{
    "defaultViewers": {
        "markdown": "Notebook"
    }
}

supposed to work now (for double-clicking from the file menu)? For me it doesn't seem to on jlab 3.1.4 and jupytext 1.10.3, even despite Markdown Preview works.

@astrojuanlu
Copy link

Since Binder now uses JupyterLab by default, this got a bit more annoying. I really like jupytext so I'll stick to the classic Notebook interface for the time being.

@mwouts
Copy link
Owner Author

mwouts commented Nov 30, 2021

Hi everyone, thanks to @fcollonval 's work on this we can now open text notebooks with a single click in Jupyter Lab. Please install jupytext==1.13.2 and follow the section With a click on the text file in JupyterLab in the documentation.

Note that links to .md notebooks in a notebook still open with the Markdown view at the moment. We want to make this configurable, but for this we will need a fix on JupyterLab (@fcollonval I see that you have a PR for this at jupyterlab/jupyterlab#11541, thank you!)

mwouts added a commit that referenced this issue Dec 9, 2021
* Add a mention of default_setting_overrides.json + links to .md files

* Require jupyterlab>=4.0.0a16 on Binder (#271)

* Use original case for .md anchors
@mwouts
Copy link
Owner Author

mwouts commented Dec 9, 2021

In jupyterlab>=4.0.0a16, when the default editor for text notebooks is "Jupytext Notebook" (with e.g. this default_setting_overrides.json ), then .md links do open as notebooks. And anchors do work (but the case must match, see #891).

You can try this yourself at https://mybinder.org/v2/gh/mwouts/jupytext/main?urlpath=lab/tree/README.md

@paulrougieux
Copy link

I'm on version jupyterlab-4.0.0a17. Editing markdown files as notebooks works when I right click on the markdown file, "open with Jupyter Notebook", but I don't manage to set this as the default. I don't see the configure default editor menu mentioned in this SO Answer.

@mwouts
Copy link
Owner Author

mwouts commented Dec 16, 2021

Hello @paulrougieux , well

  1. I am afraid the SO question is for VS Code, not Jupyter :)
  2. To open .md files as notebooks by default, you need to change your Jupyter configuration, see the paragraph on how to open text files as notebooks "With a click on the text file in JupyterLab (New)" at README/Install

@nthiery
Copy link
Contributor

nthiery commented Jan 11, 2023

For the record: opening linked jupytext markdown files as notebooks now not
only work with jupyter lab 4.*, but also with jupyterlab 3.6 (to pre precise, 3.6rc0),
thanks to a backport by @fcollonval . So very very soon, no more need to rely on a
prerelease of JupyterLab.

jupyterlab/jupyterlab#13743

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
8 participants