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.
My .ipynb test file revealed a bug in the *get_ipynb_header* function. I
changed:
end = notebook.find('# ---', 1) + 4
to:
end = notebook.find('# ---', start + 4) + 4
With this change the function returns the expected header. And now
everything works!
Thomas, your script does a creditable job already. I'll focus on your
approach.
Leo's markdown importer does less well, although conceivably the importer
could be re-imagined.
Edward
P.S. Here is the prototype that uses Leo's markdown importer.
import io
import jupytext
from leo.plugins.importers.markdown import do_import
# Read the .ipynb file into contents (pseudo-python)
notebook = jupytext.read(path, fmt=fmt)
fmt = 'py:percent'
with io.StringIO() as f:
jupytext.write(notebook, f, fmt=fmt)
contents = f.getvalue()
# Use Leo's markdown importer to create an outline.
p = g.findNodeAnywhere(c, 'markdown-test')
p.b = ''
p.deleteAllChildren()
do_import(c, p, contents)
c.redraw(p)
EKR
--
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 view this discussion visit
https://groups.google.com/d/msgid/leo-editor/c9b551f4-f1f2-4361-8338-6ff1f97841e8n%40googlegroups.com.