Weave.jl/src/pandoc.jl

86 lines
2.3 KiB
Julia
Raw Normal View History

"""
2016-04-20 17:34:24 +02:00
`pandoc2html(formatted::AbstractString, doc::WeaveDoc)`
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")
path, wsource = splitdir(abspath(doc.source))
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)
2016-04-20 16:04:38 +02:00
html =""
outname = basename(outname)
2016-04-20 16:04:38 +02:00
try
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
-V headerscript=$header_script
2016-04-28 15:11:45 +02:00
-o $outname`)
println(pandoc_in, formatted)
close(pandoc_in)
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())
outname = basename(outname)
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
end