mirror of https://github.com/mpastell/Weave.jl
Implement adding plotly javascript to html file header using pandoc when needed. Remove Raleway, closes #45
parent
901050a32f
commit
544ae925e2
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
18
src/plots.jl
18
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"(?=<div)")
|
||||
#script = lstrip(start[1]) #local
|
||||
|
||||
#TODO insert into header
|
||||
#script = "<script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script>"
|
||||
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 *= "<script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></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 = "<script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></script>"
|
||||
body = Plots.PlotlyJS.html_body(plot.o.plot)
|
||||
|
||||
if report.first_plot
|
||||
report.rich_output *= "\n" * script
|
||||
report.header_script *= "<script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></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 = "<script src=\"https://cdn.plot.ly/plotly-latest.min.js\"></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
|
||||
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
|
@ -1,21 +1,18 @@
|
|||
<style type="text/css">
|
||||
@font-face {
|
||||
font-family: 'Raleway';
|
||||
font-family: 'Garamond';
|
||||
font-style: normal;
|
||||
font-weight: 300;
|
||||
src: local('Raleway Light'), local('Raleway-Light'), url(http://fonts.gstatic.com/s/raleway/v9/-_Ctzj9b56b8RgXW8FArifk_vArhqVIZ0nv9q090hN8.woff2) format('woff2');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Raleway';
|
||||
font-family: 'Garamond';
|
||||
font-style: normal;
|
||||
font-weight: 400;
|
||||
src: local('Raleway'), url(http://fonts.gstatic.com/s/raleway/v9/0dTEPzkLWceF7z0koJaX1A.woff2) format('woff2');
|
||||
}
|
||||
@font-face {
|
||||
font-family: 'Raleway';
|
||||
font-family: 'Garamond';
|
||||
font-style: normal;
|
||||
font-weight: 600;
|
||||
src: local('Raleway SemiBold'), local('Raleway-SemiBold'), url(http://fonts.gstatic.com/s/raleway/v9/xkvoNo9fC8O2RDydKj12b_k_vArhqVIZ0nv9q090hN8.woff2) format('woff2');
|
||||
}
|
||||
html {
|
||||
font-family: sans-serif; /* 1 */
|
||||
|
|
|
@ -17,11 +17,15 @@ $endif$
|
|||
|
||||
<!-- TODO check if math works with plotly -->
|
||||
<!-- Need to load plotly before Mathjax or pandoc equations don't work -->
|
||||
|
||||
<script src="https://cdn.plot.ly/plotly-latest.min.js"></script>
|
||||
$headerscript$
|
||||
|
||||
$if(math)$
|
||||
$math$
|
||||
<script type="text/javascript">
|
||||
var fileref=document.createElement('script')
|
||||
fileref.setAttribute("type","text/javascript")
|
||||
fileref.setAttribute("src", "http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML")
|
||||
document.getElementsByTagName("head")[0].appendChild(fileref)
|
||||
</script>
|
||||
$endif$
|
||||
|
||||
$for(header-includes)$
|
||||
|
|
Loading…
Reference in New Issue