Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Write display() calls in markdown output #256

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

gbruer15
Copy link
Contributor

@fredrikekre I made some changes to get the display() calls rendered for the markdown output, but I don't understand the multiple MIMEs for the same display() call. And I don't understand the use for the split_mime() call.

So this is an initial fix, but it seems to duplicate output to both plain text and HTML. Can you advise on the correct behavior?

Fixes #255

@fredrikekre
Copy link
Owner

Jupyter notebooks are a bit different because they can store multiple representations. In the case of Markdown I think we should mirror Documenter and only display a single one perhaps.

@fredrikekre
Copy link
Owner

I don't remember what Documenter does with explicit display calls, do you know?

@gbruer15
Copy link
Contributor Author

I don't know, but I'll look into it.

@gbruer15 gbruer15 marked this pull request as draft September 19, 2024 15:25
@gbruer15
Copy link
Contributor Author

It looks like Documenter.jl does not handle display() calls. It does mime dict processing of the single output of the cell:

Also, QuartoNotebookRunner.jl does similar processing but just hands the outputs back to quarto:

I think Literate.jl markdown format just needs something like the domify() of Documenter.jl.

@gbruer15 gbruer15 marked this pull request as ready for review September 23, 2024 15:05
@gbruer15
Copy link
Contributor Author

This is working now with images, markdown, and plain text outputs. I don't know the right way to handle displaying the latex. Right now, I simply wrapped it in "latex" and "".

@fredrikekre
Copy link
Owner

I will find time to review, but can you comment on what happens if there is an explicit display call and a value that can be showed in the same cell?

@gbruer15
Copy link
Contributor Author

The results of the display calls are shown in order, and then the return value is displayed.

Example

Consider this example script:

struct DF{N} x end
DF(x) = DF{x}(x)
Base.show(io::IO, ::MIME"text/plain", df::DF{1}) = print(io, "DF($(df.x)) as text/plain")
Base.show(io::IO, ::MIME"text/html", df::DF{2}) = print(io, "DF($(df.x)) as text/html")
Base.show(io::IO, ::MIME"image/png", df::DF{3}) = print(io, "DF($(df.x)) as image/png")
Base.show(io::IO, ::MIME"text/markdown", df::DF{4}) = print(io, "DF($(df.x)) as text/markdown")
Base.show(io::IO, ::MIME"text/latex", df::DF{5}) = print(io, "DF($(df.x)) as text/latex")
Base.show(io::IO, ::MIME"image/svg+xml", df::DF{6}) = print(io, "DF($(df.x)) as image/svg+xml")
Base.show(io::IO, ::MIME"image/png", df::DF{7}) = print(io, "DF($(df.x)) as image/png")
#-
foreach(display, DF(i) for i in 1:6)
DF(7)

Notebook (as generated)

The generated notebook can't display the images because they aren't valid, and the markdown and svg output aren't right.

image

Notebook (after running kernel)

If I run the kernel, the markdown and is more correct, although I'm not sure it they should look like. And the svg doesn't show up, probably due to being invalid.

image

Markdown (execute=false)

The markdown example with execute=false doesn't show the displays.

image

Markdown (execute=true)

The markdown example with execute=true doesn't show the images, probably since they're invalid. But I have tested with actual images and they showed up correctly.

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Fetching output of display
2 participants