Expanding `@repl` blocks in REPL and Jupyter

While writing documentation, I am making large use of the @repl blocks with Documenter.jl. However, it seems that these blocks are not expanded automatically in the REPL or in Jupyter.

Is there a way to expand the @repl blocks in the REPL, when accessing the documentation with ? ?

1 Like

Nope. The evaluation of at-repl blocks is provided by Documenter, so base Julia doesn’t know anything about them. Also, note that Documenter does not evaluate at-repl blocks that are in docstrings either (just the ones on Markdown pages).

Theoretically, one could implement some sort of DocStringExtensions-like approach for this. But this requires the code to actually be evaluated when you pull up docstrings, and that can be expensive, and I feel that this will likely be a footgun, often leading to bad UX.

Instead, you should use doctests for this. Documenter can help you keep them up to date.

2 Likes

Thanks! Yeah, I feared so. Manually updating a bunch of jldoctests felt painful. I didn’t know that you could have Documenter to fix them automatically, thanks!

Yep. For new doctests, my strategy sometimes is to just write something like

```jldoctest
julia> foo()

julia> bar()

```

commit that (in case doctest fixing messes it up somehow), and then run the doctest fixing functionality on them, to populate the outputs.