Open ForceBru opened 9 months ago
I totally see the use case. Couple reasons that could make this difficult (mostly thinking out loud)
We have PNG export. Would a good PDF export satisfy your needs? Or would you like some interactivity still (e.g. hiding code, scrolling tables)?
Some strawman options that have trade-offs:
Going to update from a bug to enhancement - I see this more as "static html offline support"
Would a good PDF export satisfy your needs?
Yep, I think having a static export would be useful, especially for shareability, as stated in marimo's goals in the README. Just send someone a PDF and they can view it on a potato.
Or would you like some interactivity still (e.g. hiding code, scrolling tables)?
Personally, I don't see the need for interactivity in an exported notebook. In an app - sure, in a notebook I'm currently running and editing - definitely. In a raw HTML file? Hiding code could be nice, maybe.
I think a simple (!) HTML file is already fine for static export:
<img>
tag using base64. Also <svg>
.As for inlining LaTeX, I found this just now: https://dev.to/uetchy/math-api-latex-math-as-svg-image-m4p. Apparently, it converts LaTeX markup to SVG images, so one can just put them into the HTML. Looks like SVG has been supported by browsers since at least 2012, which should increase shareability/viewability even further (that is, probably everyone can view SVG). That project is opensource, so in theory, marimo could do something like this during export:
Unfortunately, that's just a theory...
+1. Offline static HTML is part of my workflow with Jupyter that I'd love to see in Marimo to fully jump ship.
One thing I've been using recently that wouldn't be satisfied with a PDF is embedding interactive plotly plots to the notebook. With some hoops those survive the export to static HTML.
@jeffmelville, @ForceBru
We have a way to HTML export now from the CLI: marimo export html notebook.py -o notebook.html
. Could you use some other CLI tool (e.g. [pywebcopy](https://pypi.org/project/pywebcopy/, or plain wget
) in order to make the html file offline?
TL;DR:
marimo export json
could produce a list of dictionaries representing cells. With that, people could come together and transpile that JSON to HTML, PDF and whatever else.use some other CLI tool ... in order to make the html file offline
Not sure how that'd work? The PyWebCopy documentation says that "PyWebCopy can "crawl" an entire website and download everything it sees in an effort to create a reasonable facsimile of the source website". Does it mean I should run PyWebCopy on the HTML generated by marimo? I guess that'd probably work, but why? This seems unnecessarily complicated. However, I likely don't know enough about webdev to understand what's complicated and what isn't. I really want to tinker with marimo and build a prototype HTML export tool that'd export to the simplest HTML possible that'd work without JavaScript on any potato.
Here's my basic plan if I ever have the time:
print
output (just raw text)<img>
with src="data:..."
. The goal is to make a self-contained file, so images will have to become nasty base64 strings...<details>
might be of use.<pre>
as raw text.<span>
. Make sure to not mess up indentation, keep comments and every minute detail of the code.
<textarea>
and not editable..py
file) in a collapsible (via <details>
) <textarea>
tag. The user should be able to easily extract the original code from the exported file.<textarea disabled>
tag. It's scrollable and thus doesn't take too much space when the output is very long.The result would be a really basic HTML table with almost no interactive elements (except for <details>
):
As usual, that's just a theory... I really should start hacking on some code to translate Python source to highlighted HTML - that shouldn't be too hard. If only marimo could export notebooks to well-structured JSON. In that case I could just ingest the JSON and convert it to HTML or whatever else, really.
Describe the bug
How to reproduce
marimo edit random_notebook.py
. Fill it with random code likeprint("Hello")
, execute & save.<script type="module" crossorigin="anonymous" src="https://cdn.jsdelivr.net/npm/@marimo-team/frontend@0.1.77/dist/assets/index-z8usByTF.js">
since I'm offline and disabled caches.Why I think this is not good
IMO, exported notebooks should be more accessible than the editable notebook that pops up with
marimo edit
. One should be able to read it almost anywhere, like a PDF document or an image. Especially given that the exported notebook is a static HTML file with mostly text (my code) - I should be able to view it offline.Environment
Code to reproduce
Code doesn't matter, any code will do.