fredrikekre / Literate.jl

Simple package for literate programming in Julia
https://fredrikekre.github.io/Literate.jl
Other
545 stars 64 forks source link

Fetching output of display #255

Open gbruer15 opened 1 month ago

gbruer15 commented 1 month ago

I have some display() calls in my code, but it seems they're not showing up in the generated markdown.

128 marks this as fixed, but perhaps it only fixed it for the notebook output.

@fredrikekre This was fixed for notebooks in https://github.com/fredrikekre/Literate.jl/commit/ceff7a36be2a9152d853257bac97be00d915ba8e and a TODO was added for markdown. Would the fix for markdown be similar to the notebook fix? Or is it more complicated? If it's straightforward, I can make a PR with the changes for markdown.

fredrikekre commented 1 month ago

Do you have a MWE?

gbruer15 commented 1 month ago

Here is a minimum example.

$ cat example.jl
struct DF x end
Base.show(io::IO, ::MIME"text/plain", df::DF) = print(io, "DF($(df.x)) as text/plain")
Base.show(io::IO, ::MIME"text/html", df::DF) = print(io, "DF($(df.x)) as text/html")
Base.show(io::IO, ::MIME"text/latex", df::DF) = print(io, "DF($(df.x)) as text/latex")
#-
foreach(display, [DF(1), DF(2)])
DF(3)
#-
display(MIME("text/latex"), DF(4))
$ julia example.jl 
DF(1) as text/plain
DF(2) as text/plain
DF(4) as text/latex
$ julia --project=. -e 'import Literate; Literate.markdown("example.jl", "mfe"; execute=true)'
[ Info: generating markdown page from `~/a/curr_research/Literate.jl/example.jl`
[ Info: writing result to `~/a/curr_research/Literate.jl/mfe/example.md`
$ cat mfe/example.md 
```@meta
EditURL = "../example.jl"
struct DF x end
Base.show(io::IO, ::MIME"text/plain", df::DF) = print(io, "DF($(df.x)) as text/plain")
Base.show(io::IO, ::MIME"text/html", df::DF) = print(io, "DF($(df.x)) as text/html")
Base.show(io::IO, ::MIME"text/latex", df::DF) = print(io, "DF($(df.x)) as text/latex")
foreach(display, [DF(1), DF(2)])
DF(3)
DF(3) as text/html
display(MIME("text/latex"), DF(4))

This page was generated using Literate.jl.