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)
|
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("types.jl")
|
||||||
include("config.jl")
|
include("config.jl")
|
||||||
include("WeaveMarkdown/markdown.jl")
|
include("WeaveMarkdown/markdown.jl")
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
|
# TODO: follow RMarkdown convention more
|
||||||
const _DEFAULT_PARAMS = Dict{Symbol,Any}(
|
const _DEFAULT_PARAMS = Dict{Symbol,Any}(
|
||||||
:echo => true,
|
:echo => true,
|
||||||
:results => "markup",
|
:results => "markup",
|
||||||
:hold => false,
|
:hold => false,
|
||||||
:fig => true,
|
:fig => true,
|
||||||
:include => true,
|
|
||||||
:eval => true,
|
:eval => true,
|
||||||
:tangle => true,
|
:tangle => true,
|
||||||
:cache => false,
|
:cache => false,
|
||||||
|
@ -18,7 +18,6 @@ const _DEFAULT_PARAMS = Dict{Symbol,Any}(
|
||||||
:label => nothing,
|
:label => nothing,
|
||||||
:wrap => true,
|
:wrap => true,
|
||||||
:line_width => 75,
|
:line_width => 75,
|
||||||
:engine => "julia",
|
|
||||||
:fig_ext => nothing,
|
:fig_ext => nothing,
|
||||||
:fig_pos => nothing,
|
:fig_pos => nothing,
|
||||||
:fig_env => nothing,
|
:fig_env => nothing,
|
||||||
|
|
|
@ -2,14 +2,14 @@ using Markdown, .WeaveMarkdown
|
||||||
|
|
||||||
# Contains report global properties
|
# Contains report global properties
|
||||||
mutable struct Report <: AbstractDisplay
|
mutable struct Report <: AbstractDisplay
|
||||||
cwd::AbstractString
|
cwd::String
|
||||||
basename::AbstractString
|
basename::String
|
||||||
format::WeaveFormat
|
format::WeaveFormat
|
||||||
rich_output::AbstractString
|
rich_output::String
|
||||||
fignum::Int
|
fignum::Int
|
||||||
figures::Vector{String}
|
figures::Vector{String}
|
||||||
cur_chunk::Any
|
cur_chunk::Union{Nothing,CodeChunk}
|
||||||
mimetypes::Array{AbstractString}
|
mimetypes::Vector{String}
|
||||||
first_plot::Bool
|
first_plot::Bool
|
||||||
header_script::String
|
header_script::String
|
||||||
throw_errors::Bool
|
throw_errors::Bool
|
||||||
|
|
|
@ -4,14 +4,13 @@ using Base64, ..Plots, ..Weave
|
||||||
|
|
||||||
|
|
||||||
# Pre-execute hooks to set the plot size for the chunk
|
# 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]
|
w = chunk.options[:fig_width] * chunk.options[:dpi]
|
||||||
h = chunk.options[:fig_height] * chunk.options[:dpi]
|
h = chunk.options[:fig_height] * chunk.options[:dpi]
|
||||||
Plots.default(size = (w, h))
|
Plots.default(size = (w, h))
|
||||||
return chunk
|
|
||||||
end
|
end
|
||||||
|
|
||||||
Weave.push_preexecute_hook(plots_set_size)
|
Weave.push_preexecution_hook!(plots_set_size)
|
||||||
|
|
||||||
# PNG or SVG is not working, output html
|
# PNG or SVG is not working, output html
|
||||||
function Base.display(
|
function Base.display(
|
||||||
|
|
|
@ -91,9 +91,7 @@ function format_chunk(chunk::CodeChunk, docformat)
|
||||||
|
|
||||||
# Handle figures
|
# Handle figures
|
||||||
if chunk.options[:fig] && length(chunk.figures) > 0
|
if chunk.options[:fig] && length(chunk.figures) > 0
|
||||||
if chunk.options[:include]
|
result *= formatfigures(chunk, docformat)
|
||||||
result *= formatfigures(chunk, docformat)
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return result
|
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
|
return chunk
|
||||||
end
|
end
|
||||||
|
|
||||||
# Run preexecute_hooks
|
execute_prehooks!(chunk)
|
||||||
for hook in preexecute_hooks
|
|
||||||
chunk = Base.invokelatest(hook, chunk)
|
|
||||||
end
|
|
||||||
|
|
||||||
report.fignum = 1
|
report.fignum = 1
|
||||||
report.cur_chunk = chunk
|
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)
|
chunk.result = run_code(doc, chunk, report, mod)
|
||||||
|
|
||||||
# Run post_execute chunks
|
execute_posthooks!(chunk)
|
||||||
for hook in postexecute_hooks
|
|
||||||
chunk = Base.invokelatest(hook, chunk)
|
|
||||||
end
|
|
||||||
|
|
||||||
chunks = if chunk.options[:term]
|
chunks = if chunk.options[:term]
|
||||||
collect_term_results(chunk)
|
collect_term_results(chunk)
|
||||||
|
@ -296,13 +290,28 @@ function eval_chunk(doc::WeaveDoc, chunk::CodeChunk, report::Report, mod::Module
|
||||||
collect_results(chunk)
|
collect_results(chunk)
|
||||||
end
|
end
|
||||||
|
|
||||||
# else
|
|
||||||
# chunk.options[:fig] && (chunk.figures = copy(report.figures))
|
|
||||||
# end
|
|
||||||
|
|
||||||
return chunks
|
return chunks
|
||||||
end
|
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)
|
clear_module!(mod::Module)
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue