2016-04-20 14:41:54 +02:00
|
|
|
|
|
|
|
|
|
|
|
"""
|
2016-04-20 17:34:24 +02:00
|
|
|
`pandoc2html(formatted::AbstractString, doc::WeaveDoc)`
|
2016-04-20 14:41:54 +02:00
|
|
|
|
|
|
|
Convert output from pandoc markdown to html using Weave.jl template
|
|
|
|
"""
|
2016-04-24 14:02:03 +02:00
|
|
|
function pandoc2html(formatted::AbstractString, doc::WeaveDoc, outname::AbstractString)
|
2016-12-12 18:25:51 +01:00
|
|
|
weavedir = dirname(@__FILE__)
|
|
|
|
html_template = joinpath(weavedir, "../templates/pandoc_skeleton.html")
|
|
|
|
css_template = joinpath(weavedir, "../templates/pandoc_skeleton.css")
|
2016-04-20 14:41:54 +02:00
|
|
|
|
|
|
|
path, wsource = splitdir(abspath(doc.source))
|
|
|
|
wversion = string(Pkg.installed("Weave"))
|
2016-04-29 16:32:05 +02:00
|
|
|
wtime = string(Date(now()))
|
2016-04-20 14:41:54 +02:00
|
|
|
|
2016-11-02 22:45:32 +01:00
|
|
|
#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
|
|
|
|
|
2016-04-20 14:41:54 +02:00
|
|
|
#Change path for pandoc
|
|
|
|
old_wd = pwd()
|
|
|
|
cd(doc.cwd)
|
2016-04-20 16:04:38 +02:00
|
|
|
html =""
|
2016-04-24 15:08:18 +02:00
|
|
|
outname = basename(outname)
|
2016-04-20 14:41:54 +02:00
|
|
|
|
2016-04-20 16:04:38 +02:00
|
|
|
try
|
2016-11-02 22:45:32 +01:00
|
|
|
pandoc_out, pandoc_in, proc = readandwrite(`pandoc -R -s --mathjax="" --highlight-style=tango
|
|
|
|
--template $html_template -H $css_template $self_contained
|
2016-04-25 08:11:59 +02:00
|
|
|
-V wversion=$wversion -V wtime=$wtime -V wsource=$wsource
|
2016-11-02 22:45:32 +01:00
|
|
|
-V headerscript=$header_script
|
2016-04-28 15:11:45 +02:00
|
|
|
-o $outname`)
|
|
|
|
println(pandoc_in, formatted)
|
|
|
|
|
|
|
|
close(pandoc_in)
|
2016-11-01 11:03:48 +01:00
|
|
|
proc_output = readstring(pandoc_out)
|
2016-04-20 17:34:24 +02:00
|
|
|
cd(old_wd)
|
2016-04-28 15:11:45 +02:00
|
|
|
catch e
|
2016-04-20 16:04:38 +02:00
|
|
|
cd(old_wd)
|
2016-04-28 15:11:45 +02:00
|
|
|
warn("Error converting document to HTML")
|
|
|
|
throw(e)
|
2016-04-20 16:04:38 +02:00
|
|
|
end
|
2016-04-20 17:34:24 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
"""
|
|
|
|
`pandoc2pdf(formatted::AbstractString, doc::WeaveDoc)`
|
|
|
|
|
|
|
|
Convert output from pandoc markdown to pdf using Weave.jl template
|
|
|
|
"""
|
2016-04-24 14:02:03 +02:00
|
|
|
function pandoc2pdf(formatted::AbstractString, doc::WeaveDoc, outname::AbstractString)
|
2016-12-12 18:25:51 +01:00
|
|
|
weavedir = dirname(@__FILE__)
|
|
|
|
header_template = joinpath(weavedir, "../templates/pandoc_header.txt")
|
2016-04-20 17:34:24 +02:00
|
|
|
|
|
|
|
path, wsource = splitdir(abspath(doc.source))
|
|
|
|
wversion = string(Pkg.installed("Weave"))
|
|
|
|
wtime = Date(now())
|
2016-04-24 15:08:18 +02:00
|
|
|
outname = basename(outname)
|
2016-04-20 14:41:54 +02:00
|
|
|
|
2016-04-20 17:34:24 +02:00
|
|
|
#Change path for pandoc
|
|
|
|
old_wd = pwd()
|
|
|
|
cd(doc.cwd)
|
|
|
|
html =""
|
|
|
|
|
|
|
|
info("Done executing code. Running xelatex")
|
|
|
|
try
|
2016-04-28 15:11:45 +02:00
|
|
|
pandoc_out, pandoc_in, proc = readandwrite(`pandoc -R -s --latex-engine=xelatex --highlight-style=tango
|
2016-04-25 08:11:59 +02:00
|
|
|
--include-in-header=$header_template
|
2016-11-02 08:54:45 +01:00
|
|
|
-V fontsize=12pt -o $outname`)
|
2016-04-28 15:11:45 +02:00
|
|
|
println(pandoc_in, formatted)
|
|
|
|
|
|
|
|
close(pandoc_in)
|
|
|
|
proc_output = readall(pandoc_out)
|
2016-04-20 17:34:24 +02:00
|
|
|
cd(old_wd)
|
2016-04-28 15:11:45 +02:00
|
|
|
catch e
|
2016-04-20 17:34:24 +02:00
|
|
|
cd(old_wd)
|
2016-04-28 15:11:45 +02:00
|
|
|
warn("Error converting document to pdf")
|
|
|
|
throw(e)
|
2016-04-20 17:34:24 +02:00
|
|
|
end
|
2016-04-20 14:41:54 +02:00
|
|
|
end
|