Weave.jl/src/pandoc.jl

69 lines
1.9 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)
html_template = joinpath(Pkg.dir("Weave"), "templates/pandoc_skeleton.html")
css_template = joinpath(Pkg.dir("Weave"), "templates/pandoc_skeleton.css")
path, wsource = splitdir(abspath(doc.source))
wversion = string(Pkg.installed("Weave"))
wtime = Date(now())
#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
2016-04-25 08:11:59 +02:00
open(`pandoc -R -s --mathjax="" --self-contained --highlight-style=tango
--template $html_template --include-in-header=$css_template
-V wversion=$wversion -V wtime=$wtime -V wsource=$wsource
-o $outname`, "w", STDOUT) do io
println(io, formatted)
end
2016-04-20 17:34:24 +02:00
cd(old_wd)
2016-04-20 16:04:38 +02:00
catch
cd(old_wd)
error("Unable to convert to html, check that you have pandoc installed and in your path")
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-04-20 17:34:24 +02:00
header_template = joinpath(Pkg.dir("Weave"), "templates/pandoc_header.txt")
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-25 08:11:59 +02:00
open(`pandoc -R -s --latex-engine=xelatex --highlight-style=tango
--include-in-header=$header_template
-V fontsize=12pt
-o $outname`, "w", STDOUT) do io
println(io, formatted)
end
2016-04-20 17:34:24 +02:00
cd(old_wd)
catch
cd(old_wd)
2016-04-25 08:11:59 +02:00
error("Unable to convert to pdf, check that you have pandoc and xelatex installed and in your path")
2016-04-20 17:34:24 +02:00
end
end