mirror of https://github.com/mpastell/Weave.jl
commit
e0a9d044cd
12
src/Weave.jl
12
src/Weave.jl
|
@ -321,18 +321,6 @@ end
|
|||
|
||||
include_weave(source, informat = nothing) = include_weave(Main, source, informat)
|
||||
|
||||
# Hooks to run before and after chunks, this is form IJulia,
|
||||
# but note that Weave hooks take the chunk as input
|
||||
const preexecute_hooks = Function[]
|
||||
push_preexecute_hook(f::Function) = push!(preexecute_hooks, f)
|
||||
pop_preexecute_hook(f::Function) =
|
||||
splice!(preexecute_hooks, findfirst(x -> x == f, preexecute_hooks))
|
||||
|
||||
const postexecute_hooks = Function[]
|
||||
push_postexecute_hook(f::Function) = push!(postexecute_hooks, f)
|
||||
pop_postexecute_hook(f::Function) =
|
||||
splice!(postexecute_hooks, findfirst(x -> x == f, postexecute_hooks))
|
||||
|
||||
include("types.jl")
|
||||
include("config.jl")
|
||||
include("WeaveMarkdown/markdown.jl")
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
# TODO: follow RMarkdown convention more
|
||||
const _DEFAULT_PARAMS = Dict{Symbol,Any}(
|
||||
:echo => true,
|
||||
:results => "markup",
|
||||
:hold => false,
|
||||
:fig => true,
|
||||
:include => true,
|
||||
:eval => true,
|
||||
:tangle => true,
|
||||
:cache => false,
|
||||
|
@ -18,7 +18,6 @@ const _DEFAULT_PARAMS = Dict{Symbol,Any}(
|
|||
:label => nothing,
|
||||
:wrap => true,
|
||||
:line_width => 75,
|
||||
:engine => "julia",
|
||||
:fig_ext => nothing,
|
||||
:fig_pos => nothing,
|
||||
:fig_env => nothing,
|
||||
|
|
|
@ -2,14 +2,14 @@ using Markdown, .WeaveMarkdown
|
|||
|
||||
# Contains report global properties
|
||||
mutable struct Report <: AbstractDisplay
|
||||
cwd::AbstractString
|
||||
basename::AbstractString
|
||||
cwd::String
|
||||
basename::String
|
||||
format::WeaveFormat
|
||||
rich_output::AbstractString
|
||||
rich_output::String
|
||||
fignum::Int
|
||||
figures::Vector{String}
|
||||
cur_chunk::Any
|
||||
mimetypes::Array{AbstractString}
|
||||
cur_chunk::Union{Nothing,CodeChunk}
|
||||
mimetypes::Vector{String}
|
||||
first_plot::Bool
|
||||
header_script::String
|
||||
throw_errors::Bool
|
||||
|
|
|
@ -4,14 +4,13 @@ using Base64, ..Plots, ..Weave
|
|||
|
||||
|
||||
# Pre-execute hooks to set the plot size for the chunk
|
||||
function plots_set_size(chunk)
|
||||
function plots_set_size!(chunk)
|
||||
w = chunk.options[:fig_width] * chunk.options[:dpi]
|
||||
h = chunk.options[:fig_height] * chunk.options[:dpi]
|
||||
Plots.default(size = (w, h))
|
||||
return chunk
|
||||
end
|
||||
|
||||
Weave.push_preexecute_hook(plots_set_size)
|
||||
Weave.push_preexecution_hook!(plots_set_size)
|
||||
|
||||
# PNG or SVG is not working, output html
|
||||
function Base.display(
|
||||
|
|
|
@ -91,9 +91,7 @@ function format_chunk(chunk::CodeChunk, docformat)
|
|||
|
||||
# Handle figures
|
||||
if chunk.options[:fig] && length(chunk.figures) > 0
|
||||
if chunk.options[:include]
|
||||
result *= formatfigures(chunk, docformat)
|
||||
end
|
||||
result *= formatfigures(chunk, docformat)
|
||||
end
|
||||
|
||||
return result
|
||||
|
|
33
src/run.jl
33
src/run.jl
|
@ -269,10 +269,7 @@ function eval_chunk(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module
|
|||
return chunk
|
||||
end
|
||||
|
||||
# Run preexecute_hooks
|
||||
for hook in preexecute_hooks
|
||||
chunk = Base.invokelatest(hook, chunk)
|
||||
end
|
||||
execute_prehooks!(chunk)
|
||||
|
||||
report.fignum = 1
|
||||
report.cur_chunk = chunk
|
||||
|
@ -283,10 +280,7 @@ function eval_chunk(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module
|
|||
|
||||
chunk.result = run_code(doc, chunk, report, mod)
|
||||
|
||||
# Run post_execute chunks
|
||||
for hook in postexecute_hooks
|
||||
chunk = Base.invokelatest(hook, chunk)
|
||||
end
|
||||
execute_posthooks!(chunk)
|
||||
|
||||
chunks = if chunk.options[:term]
|
||||
collect_term_results(chunk)
|
||||
|
@ -296,13 +290,28 @@ function eval_chunk(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module
|
|||
collect_results(chunk)
|
||||
end
|
||||
|
||||
# else
|
||||
# chunk.options[:fig] && (chunk.figures = copy(report.figures))
|
||||
# end
|
||||
|
||||
return chunks
|
||||
end
|
||||
|
||||
# Hooks to run before and after chunks, this is form IJulia,
|
||||
const preexecution_hooks = Function[]
|
||||
push_preexecution_hook!(f::Function) = push!(preexecution_hooks, f)
|
||||
function pop_preexecution_hook!(f::Function)
|
||||
i = findfirst(x -> x == f, preexecution_hooks)
|
||||
isnothing(i) && error("this function has not been registered in the pre-execution hook yet")
|
||||
return splice!(preexecution_hooks, i)
|
||||
end
|
||||
execute_prehooks!(chunk::CodeChunk) = for prehook in preexecution_hooks; Base.invokelatest(prehook, chunk); end
|
||||
|
||||
const postexecution_hooks = Function[]
|
||||
push_postexecution_hook!(f::Function) = push!(postexecution_hooks, f)
|
||||
function pop_postexecution_hook!(f::Function)
|
||||
i = findfirst(x -> x == f, postexecution_hooks)
|
||||
isnothing(i) && error("this function has not been registered in the post-execution hook yet")
|
||||
return splice!(postexecution_hooks, i)
|
||||
end
|
||||
execute_posthooks!(chunk::CodeChunk) = for posthook in postexecution_hooks; Base.invokelatest(posthook, chunk); end
|
||||
|
||||
"""
|
||||
clear_module!(mod::Module)
|
||||
|
||||
|
|
Loading…
Reference in New Issue