diff --git a/src/chunks.jl b/src/chunks.jl index c7ef082..1a5aced 100644 --- a/src/chunks.jl +++ b/src/chunks.jl @@ -7,10 +7,11 @@ type WeaveDoc cwd::AbstractString format doctype::AbstractString + header_script::String function WeaveDoc(source, chunks) path, fname = splitdir(abspath(source)) basename = splitext(fname)[1] - new(source, basename, path, chunks, "", nothing, "") + new(source, basename, path, chunks, "", nothing, "", "") end end diff --git a/src/display_methods.jl b/src/display_methods.jl index a0d9fa5..b8e7116 100644 --- a/src/display_methods.jl +++ b/src/display_methods.jl @@ -12,10 +12,11 @@ type Report <: Display cur_chunk mimetypes::Array{AbstractString} first_plot::Bool + header_script::String end function Report(cwd, basename, formatdict, mimetypes) - Report(cwd, basename, formatdict, "", "", "", 1, AbstractString[], :text, nothing, mimetypes, true) + Report(cwd, basename, formatdict, "", "", "", 1, AbstractString[], :text, nothing, mimetypes, true, "") end diff --git a/src/pandoc.jl b/src/pandoc.jl index e7d6946..9109453 100644 --- a/src/pandoc.jl +++ b/src/pandoc.jl @@ -13,6 +13,16 @@ function pandoc2html(formatted::AbstractString, doc::WeaveDoc, outname::Abstract wversion = string(Pkg.installed("Weave")) wtime = string(Date(now())) + #Header is inserted from displayed plots + header_script = doc.header_script + #info(doc.header_script) + + if header_script ≠ "" + self_contained = [] + else + self_contained = "--self-contained" + end + #Change path for pandoc old_wd = pwd() cd(doc.cwd) @@ -20,9 +30,10 @@ function pandoc2html(formatted::AbstractString, doc::WeaveDoc, outname::Abstract outname = basename(outname) try - pandoc_out, pandoc_in, proc = readandwrite(`pandoc -R -s --mathjax --highlight-style=tango - --template $html_template -c $css_template + pandoc_out, pandoc_in, proc = readandwrite(`pandoc -R -s --mathjax="" --highlight-style=tango + --template $html_template -H $css_template $self_contained -V wversion=$wversion -V wtime=$wtime -V wsource=$wsource + -V headerscript=$header_script -o $outname`) println(pandoc_in, formatted) diff --git a/src/plots.jl b/src/plots.jl index 6bf0215..43d16f3 100644 --- a/src/plots.jl +++ b/src/plots.jl @@ -18,14 +18,11 @@ function Base.display(report::Report, m::MIME"image/svg+xml", data::Plots.Plot{P start = split(splitted[1], r"(?=" - script = "" div = lstrip(start[2]) plot = join(map(lstrip, splitted[2:end]), "\n") if report.first_plot - report.rich_output *= "\n" * script + report.header_script *= "" report.first_plot = false end @@ -39,11 +36,10 @@ end #PNG or SVG is not working, output html function Base.display(report::Report, m::MIME"image/svg+xml", plot::Plots.Plot{Plots.PlotlyJSBackend}) - script = "" body = Plots.PlotlyJS.html_body(plot.o.plot) if report.first_plot - report.rich_output *= "\n" * script + report.header_script *= "" report.first_plot = false end @@ -51,15 +47,7 @@ function Base.display(report::Report, m::MIME"image/svg+xml", plot::Plots.Plot{P end function Base.display(report::Report, m::MIME"image/png", plot::Plots.Plot{Plots.PlotlyJSBackend}) - script = "" - body = Plots.PlotlyJS.html_body(plot.o.plot) - - if report.first_plot - report.rich_output *= "\n" * script - report.first_plot = false - end - - report.rich_output *= "\n" * body + display(report, MIME("image/svg+xml"), data) end diff --git a/src/run.jl b/src/run.jl index 73419ce..e501974 100644 --- a/src/run.jl +++ b/src/run.jl @@ -82,6 +82,7 @@ function Base.run(doc::WeaveDoc; doctype = :auto, plotlib=:auto, executed = [executed; result_chunks] end + doc.header_script = report.header_script popdisplay(report) diff --git a/templates/pandoc_skeleton.css b/templates/pandoc_skeleton.css index a01275f..5f19bc9 100644 --- a/templates/pandoc_skeleton.css +++ b/templates/pandoc_skeleton.css @@ -1,21 +1,18 @@