Here is a script that will take an @jupytext tree and split it out into child nodes, one node per cell. To use, make a script button for it, select a @jupytext node, and run the script. The script tries to create reasonable headlines for the nodes but of course it can't be perfect.
Thanks Thomas, It works great!Although for `jupyter lab`, its ToC is displayed according to the markdown level in the document, I think it is not a big problem to extract nodes according to cells like you did, anyway, nodes are easy to operate in Leo.
I would for sure like help with the undo. Also, I think this command should be made part of the import process. If there ever turns out to be a need for someone to look at the original flat jupytext node there could be another command for that.
Here is a script that will take an @jupytext tree and split it out into child nodes, one node per cell.
I need some guidance on edge cases before I can get the script to indent beyond one level.
I don't mind if you do the work on the script. You will get the node levels right faster than I. The main thing is the edge cases, because sure as anything somebody is going to produce a file that you would swear wouldn't happen.
Alright. I'm on it. Here's my plan:- Start with the markdown importer.
Wait! The imported file in the @jupytext node is already in juyptext format, not JSON.
Anyway, the nice jupytext people have already done that work for us.
What needs to be done for producing the different indentation levels is to:
Wait! The imported file in the @jupytext node is already in juyptext format, not JSON.
I need some guidance on edge cases before I can get the script to indent beyond one level.
On Monday, October 28, 2024 at 6:27:34 PM UTC-5 Thomas wrote:Wait! The imported file in the @jupytext node is already in juyptext format, not JSON.This hint made everything clear.- The @jupytext node must contain all the imported text.I got confused because I had edited my target node by hand.
- The script will replace the @jupytext node.
As a workaround I created a copy so could rerun the script.
On Tue, Oct 29, 2024 at 12:31 AM Thomas Passin wrote:
Ah, there are so many edge cases. My suggestion is to only extract nodes at the markdown heading level without smaller subnodes.
Spoiler: Thomas's script should enhance @jupytext rather than become a separate command. Splitting the @jupytext node into an outline can be done with complete safety.