Skip to content

Commit

Permalink
move mimetype wrapping before expansion
Browse files Browse the repository at this point in the history
  • Loading branch information
jkrumbiegel committed Jun 18, 2024
1 parent c4e6a5f commit 1443084
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions src/QuartoNotebookWorker/src/render.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,10 +47,15 @@ function _render_thunk(
# so we need to catch that and return an error cell if that's the case.
expansion = nothing
is_expansion = false
# Intercept objects prior to rendering so that we can wrap specific
# types in our own `WrapperType` to customised rendering instead of
# what the package defines itself.
# Calling the wrapping mechanism here allows it to affect expansion
value = Base.@invokelatest _mimetype_wrapper(captured.value)
if !captured.error
try
expansion = Base.@invokelatest expand(captured.value)
is_expansion = _is_expanded(captured.value, expansion)
expansion = Base.@invokelatest expand(value)
is_expansion = _is_expanded(value, expansion)
catch error
backtrace = catch_backtrace()
return ((;
Expand Down Expand Up @@ -92,7 +97,7 @@ function _render_thunk(
end
else
results = Base.@invokelatest render_mimetypes(
REPL.ends_with_semicolon(code) ? nothing : captured.value,
REPL.ends_with_semicolon(code) ? nothing : value,
cell_options;
inline,
)
Expand All @@ -105,11 +110,11 @@ function _render_thunk(
results,
display_results,
output = captured.output,
error = captured.error ? string(typeof(captured.value)) : nothing,
error = captured.error ? string(typeof(value)) : nothing,
backtrace = collect(
eachline(
IOBuffer(
clean_bt_str(captured.error, captured.backtrace, captured.value),
clean_bt_str(captured.error, captured.backtrace, value),
),
),
),
Expand Down Expand Up @@ -301,11 +306,6 @@ Base.showable(mime::MIME, w::WrapperType) = Base.showable(mime, w.value)
# for inline code chunks, `inline` should be set to `true` which causes "text/plain" output like
# what you'd get from `print` (Strings without quotes) and not from `show("text/plain", ...)`
function render_mimetypes(value, cell_options; inline::Bool = false)
# Intercept objects prior to rendering so that we can wrap specific
# types in our own `WrapperType` to customised rendering instead of
# what the package defines itself.
value = _mimetype_wrapper(value)

to_format = NotebookState.OPTIONS[]["format"]["pandoc"]["to"]

result = Dict{String,@NamedTuple{error::Bool, data::Vector{UInt8}}}()
Expand Down

0 comments on commit 1443084

Please sign in to comment.