jupyterlite-sphinx icon indicating copy to clipboard operation
jupyterlite-sphinx copied to clipboard

REPL with mixed static/dynamic mode

Open chrysn opened this issue 2 months ago • 0 comments

Problem

Currently, when writing to-be-interactive documentation (REPL style, like doctests), I have 3 choices:

(Example from https://aiocoap.readthedocs.io/en/latest/guidedtour.html#a-request:

Image
  1. Write it out in full (like doctest, nothing Jupyter-ish)
  2. Use jupyter-sphinx to have the output rendered at build time, no interactivity
  3. Use jupyterlite-sphinx to have the output rendered client-side

None of those is ideal (discarding 1 as it even requires manual rendering of the output):

  1. can not be altered easily by the user
  2. has all the JavaScript ailments (hard to access in search, slow to load esp. on mobile)

Proposed Solution

In both cases, there can be deviations between what the build-time kernel renders and what the runtime kernel renders (at latest when showing a repr with memory addresses). That's fine: Jupyter users are used to the concept of cells' outputs possibly not being up to date any more.

Simple solution

There could be a replite-ish directive that primarily renders through jupyter-sphinx, but has a button "switch to interactive", whereupon the whole element is replaced with the REPL iframe.

Advanced solution

Ideally, this would be more transparent -- the next REPL input cell could be editable right away, and only on submission would the JS magic trigger (or on editing a cell, when https://github.com/jupyterlite/jupyterlite-sphinx/issues/63 is done).

Additional context

With #316 and #317 closed, I think some of the usability difficulties for this are already out of the way. For the advanced solution, there's probably other groundwork that'd need to be done first; the simple variant could be realistic as a feature with the current code base.

chrysn avatar Sep 22 '25 08:09 chrysn