mirror of https://github.com/mpastell/Weave.jl
don't decl const for `WEAVE_ARGS`
parent
d3a7f2aea7
commit
196d4ca7ce
54
src/run.jl
54
src/run.jl
|
@ -39,7 +39,7 @@ function run_doc(
|
||||||
|
|
||||||
# New sandbox for each document with args exposed
|
# New sandbox for each document with args exposed
|
||||||
isnothing(mod) && (mod = sandbox = Core.eval(Main, :(module $(gensym(:WeaveSandBox)) end))::Module)
|
isnothing(mod) && (mod = sandbox = Core.eval(Main, :(module $(gensym(:WeaveSandBox)) end))::Module)
|
||||||
Core.eval(mod, :(const WEAVE_ARGS = $(args)))
|
Core.eval(mod, :(WEAVE_ARGS = $(args)))
|
||||||
|
|
||||||
mimetypes = doc.format.mimetypes
|
mimetypes = doc.format.mimetypes
|
||||||
|
|
||||||
|
@ -140,27 +140,17 @@ function embed_figures!(chunk::CodeChunk, cwd)
|
||||||
chunk.figures[i] = img2base64(fig, cwd)
|
chunk.figures[i] = img2base64(fig, cwd)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
embed_figures!(chunks, cwd) = embed_figures!.(chunks, Ref(cwd))
|
||||||
function embed_figures!(chunks::Vector{CodeChunk}, cwd)
|
|
||||||
for chunk in chunks
|
|
||||||
embed_figures!(chunk, cwd)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function img2base64(fig, cwd)
|
function img2base64(fig, cwd)
|
||||||
ext = splitext(fig)[2]
|
ext = splitext(fig)[2]
|
||||||
f = open(joinpath(cwd, fig), "r")
|
f = open(joinpath(cwd, fig), "r")
|
||||||
raw = read(f)
|
raw = read(f)
|
||||||
close(f)
|
close(f)
|
||||||
if ext == ".png"
|
return ext == ".png" ? "data:image/png;base64," * stringmime(MIME("image/png"), raw) :
|
||||||
return "data:image/png;base64," * stringmime(MIME("image/png"), raw)
|
ext == ".svg" ? "data:image/svg+xml;base64," * stringmime(MIME("image/svg"), raw) :
|
||||||
elseif ext == ".svg"
|
ext == ".gif" ? "data:image/gif;base64," * stringmime(MIME("image/gif"), raw) :
|
||||||
return "data:image/svg+xml;base64," * stringmime(MIME("image/svg"), raw)
|
fig
|
||||||
elseif ext == ".gif"
|
|
||||||
return "data:image/gif;base64," * stringmime(MIME("image/gif"), raw)
|
|
||||||
else
|
|
||||||
return (fig)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function run_chunk(chunk::DocChunk, doc, report, mod)
|
function run_chunk(chunk::DocChunk, doc, report, mod)
|
||||||
|
@ -274,15 +264,9 @@ function eval_chunk(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module
|
||||||
|
|
||||||
execute_posthooks!(chunk)
|
execute_posthooks!(chunk)
|
||||||
|
|
||||||
chunks = if chunk.options[:term]
|
return chunk.options[:term] ? collect_term_results(chunk) :
|
||||||
collect_term_results(chunk)
|
chunk.options[:hold] ? collect_hold_results(chunk) :
|
||||||
elseif chunk.options[:hold]
|
collect_results(chunk)
|
||||||
collect_hold_results(chunk)
|
|
||||||
else
|
|
||||||
collect_results(chunk)
|
|
||||||
end
|
|
||||||
|
|
||||||
return chunks
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Hooks to run before and after chunks, this is form IJulia,
|
# Hooks to run before and after chunks, this is form IJulia,
|
||||||
|
@ -293,7 +277,11 @@ function pop_preexecution_hook!(f::Function)
|
||||||
isnothing(i) && error("this function has not been registered in the pre-execution hook yet")
|
isnothing(i) && error("this function has not been registered in the pre-execution hook yet")
|
||||||
return splice!(preexecution_hooks, i)
|
return splice!(preexecution_hooks, i)
|
||||||
end
|
end
|
||||||
execute_prehooks!(chunk::CodeChunk) = for prehook in preexecution_hooks; Base.invokelatest(prehook, chunk); end
|
function execute_prehooks!(chunk::CodeChunk)
|
||||||
|
for prehook in preexecution_hooks
|
||||||
|
Base.invokelatest(prehook, chunk)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
const postexecution_hooks = Function[]
|
const postexecution_hooks = Function[]
|
||||||
push_postexecution_hook!(f::Function) = push!(postexecution_hooks, f)
|
push_postexecution_hook!(f::Function) = push!(postexecution_hooks, f)
|
||||||
|
@ -302,7 +290,11 @@ function pop_postexecution_hook!(f::Function)
|
||||||
isnothing(i) && error("this function has not been registered in the post-execution hook yet")
|
isnothing(i) && error("this function has not been registered in the post-execution hook yet")
|
||||||
return splice!(postexecution_hooks, i)
|
return splice!(postexecution_hooks, i)
|
||||||
end
|
end
|
||||||
execute_posthooks!(chunk::CodeChunk) = for posthook in postexecution_hooks; Base.invokelatest(posthook, chunk); end
|
function execute_posthooks!(chunk::CodeChunk)
|
||||||
|
for posthook in postexecution_hooks
|
||||||
|
Base.invokelatest(posthook, chunk)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
"""
|
"""
|
||||||
clear_module!(mod::Module)
|
clear_module!(mod::Module)
|
||||||
|
@ -341,11 +333,7 @@ function get_figname(report::Report, chunk; fignum = nothing, ext = nothing)
|
||||||
end
|
end
|
||||||
|
|
||||||
function set_rc_params(doc::WeaveDoc, fig_path, fig_ext)
|
function set_rc_params(doc::WeaveDoc, fig_path, fig_ext)
|
||||||
if isnothing(fig_ext)
|
doc.chunk_defaults[:fig_ext] = isnothing(fig_ext) ? doc.format.fig_ext : fig_ext
|
||||||
doc.chunk_defaults[:fig_ext] = doc.format.fig_ext
|
|
||||||
else
|
|
||||||
doc.chunk_defaults[:fig_ext] = fig_ext
|
|
||||||
end
|
|
||||||
doc.chunk_defaults[:fig_path] = fig_path
|
doc.chunk_defaults[:fig_path] = fig_path
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -363,9 +351,9 @@ function collect_results(chunk::CodeChunk)
|
||||||
chunk.optionstring,
|
chunk.optionstring,
|
||||||
copy(chunk.options),
|
copy(chunk.options),
|
||||||
)
|
)
|
||||||
rchunk.figures = r.figures
|
|
||||||
rchunk.output = r.stdout
|
rchunk.output = r.stdout
|
||||||
rchunk.rich_output = r.rich_output
|
rchunk.rich_output = r.rich_output
|
||||||
|
rchunk.figures = r.figures
|
||||||
push!(result_chunks, rchunk)
|
push!(result_chunks, rchunk)
|
||||||
content = ""
|
content = ""
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue