On Wednesday, March 23, 2016 at 6:13:16 AM UTC-5, Edward K. Ream wrote:

> Leo now has two *experimental* commands:
>  import/export-jupyter-notebook
> ...I'm not sure how important these commands will be.

Well, I'm sure now...

*Jupyter can now render any Leo outline!!!*

This means that *right now* Leo users can get all the cool features of both 
Leo and Jupyter.  Just export *any* Leo outline to a .ipynb file, and load 
the file into Jupyter.




*Jupyter is Leo's long-sought rendering engine!The exported notebook works 
like the rst3 command!*
A truly simple hack gives allows you to organize your Leo file as usual, 
and have the result (in Jupyter) look like what you would get using Leo's 
rst3 command.

If a 'markdown' node p (a node with @language markdown or @language rest) 
does *not* match the regex:
    
'^<[hH][123456]>'

then the export code inserts:

<hn>p.h</hn> 

at the start of p.b. n is simply:

max(6, 1+p.level()-self.root.level)

That's it!!!  We get auto-creation of headlines *in the Jupyter notebook.*

That's almost all you need to know, but let me explain in detail what 
happened.

*Improved import code*

The original code just dumped all the "hidden" data into children of the 
each cell node.  Cells were labelled "cell 1", "cell 2", etc.

The overall effect was clumsy and wonky. No wonder I doubted that anything 
good would come of it.

But today all the "cruft" children gradually went away.  For example, 
'cell_type' is represented by @language directives.  So the only remaining 
items contain important data, and 'markdown' nodes *never* have children.

*Improved export code*

The code is now completely independent of the import command.  For example, 
it generates a top-level metadata element if there is no {prefix} node.

Furthermore, the export and import code collaborate to remember Leo 
headlines.  Of course, these are invisible to Jupyter, but the <hn> tags 
*reproduce* Leo's headlines in Jupyter.

BTW, the export code has flattened the outline from day 1. At present, the 
root of the tree isn't exported, but that would be trivial to do.  Not sure 
it's a good idea.



*Summary*Lot's of incremental improvements have suddenly yield something 
spectacular. I vividly remember the shock when I saw Leo headlines in 
*imported* code.  I started to reorganize the flat nodes of a real 
notebook: 04_Neural_Networks.ipynb.  All of a sudden, it's organization 
became clear!

Folks, this is an Aha on a par with "webs are outlines in disguise":

1. We can get all of Jupyter's rendering capabilities by exporting an 
outline to an .ipynb file.

2. The export process automagically produces markdown/Jupyter headlines by 
default, but this can be over-ridden by placing <h1> ... <h6> anywhere in a 
'markdown' node.

3. The importer represents previous cruft directly in cell's body text.  
Only significant data remains.

4. The exporter will work on *any* Leo outline.

5. All of Leo's organizational prowess can now be applied to Jupyter 
notebooks!  In particular, the present export code now works much like 
Leo's rst3 command.

This is really just day one of the project.  Bugs may lurk and further 
improvements may appear. No matter. There is now an *easy* way to:

- Create Jupyter notebooks in Leo,
- Render Leo outlines using Jupyter.

A great day for Leo.  It's time to start playing with Jupyter, if you 
haven't already.  I promise, it will be fun...

Edward

-- 
You received this message because you are subscribed to the Google Groups 
"leo-editor" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/leo-editor.
For more options, visit https://groups.google.com/d/optout.

Reply via email to