The conversion script shows the power of Leo's scripting API. Here are the
lines that clean newly imported files:
def is_pure_python(p) -> bool:
return not any(
line.startswith('# %% [markdown]')
for p2 in p.self_and_subtree()
for line in g.splitLines(p2.b)
)
...
# Delete the useless Jupyter boilerplate.
for child in p.children():
if child.h == g.angleBrackets(' prefix '):
child.doDelete()
break
p.b = p.b.replace(g.angleBrackets(' prefix ') + '\n', '')
if is_pure_python(p):
# Change the language and remove all jupytext comments.
p.b = p.b.replace('@language jupytext', '@language python')
for child in p.children():
child.b = child.b.replace('# %%\n\n', '').replace('# %%\n', '')
Disable these lines to retain two-way compatibility with Jupyter Notebooks.
Onward to studying math!
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 view this discussion visit
https://groups.google.com/d/msgid/leo-editor/19cc84c4-5a12-458b-8e63-850de3db5735n%40googlegroups.com.