thebe
thebe copied to clipboard
Save edited code to persistent browser local storage
Description / Summary
One of the attractive features of the jupyterlite environment is the ability to save and open notebooks from browser local storage.
When using JupyterBook as an interactive text book, it is quite likely that the author will create examples where the reader is expected to make changes to code before running it using thebe, for example.
It would be useful if a user could:
- save the changed contents of a live code cell to local browser storage;
- be alerted to the fact that there is modified content available in local storage for a particular cell if the page is reloaded (eg the code is automatically reverted to the original when the page is reloaded);
- load code saved to local storage back into a live code cell.
Value / benefit
Users of an e-textbook would be able to persist changes they have made to live code cells.
This would add value when publishing interactive text books that encourage users to modify or create their own code, rather than simply running provided code.
Being able to persist edited code in the Jupyter Book UI means that users do no need to launch into a Jupyter notebook environment to persist their code changes. (Note that notebooks opened into a MyBinder environment from Jupyter Book may be persisted by saving them to browser storage using the jupyter-offlinenotebook extension.)
The ability to persist edited code would become even more useful in the event of being able to execute live code cell code in the browser using something like a pyodide kernel (related issue).
Implementation details
Some means for:
- [ ] uniquely identifying a live code cell;
- [ ] saving code cell contents to browser local storage;
- [ ] identifying whether modified code is available in local storage;
- [ ] alerting the user that modified code is available in local storage (either at the page level or the cell level);
- [ ] restoring persisted modified code from browser local storage into a code cell;
If modified code cell contents are automatically loaded from local storage to a code cell on page load, provide some means to:
- [ ] revert modified code cell content to original code.
See also this related Jupyter Book issue: Save Comment to Browser Storage which suggests a more general discussion about persisting modified content from a Jupyter Book UI to browser storage may be warranted?
Tasks to complete
- [ ] general discussion about the merits and possible scope of saving modified content to browser local storage; or
- [ ] limited scope discussion about persisting modified live code cell content;
- [ ] UI considerations for identifying presence of modified cell content, alerting user to it, saving and restoring modified content, restoring original content;
- [ ] security considerations?
@stevejpurves With the updates to thebe, and executing code via jupyterlite, is there a way though to using the jupyerlite browser storage mechanism to support persistence of edited code in a thebe enabled Jupyter book code cell? Or is thebe jupyerlite integration purely limited to handling code execution?
@psychemedia the jupyterlite part is really only concerned with execution but persisting back to browser storage in thebe is possible anyways - it'll be a good enhancement to make once #554 is merged