Weave.jl/src/pandoc.jl

75 lines
2.1 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-20 20:01:14 +02:00
#html = @compat readstring(
2016-04-20 17:34:24 +02:00
run(pipeline(`echo $formatted` ,
`pandoc -R -s --mathjax="" --self-contained --highlight-style=tango
2016-04-20 17:34:24 +02:00
--template $html_template --include-in-header=$css_template
-V wversion=$wversion -V wtime=$wtime -V wsource=$wsource
-o $outname`))
# )
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
run(pipeline(`echo $formatted` ,
`pandoc -R -s --latex-engine=xelatex --highlight-style=tango
2016-04-20 17:34:24 +02:00
--include-in-header=$header_template
-V fontsize=12pt
-o $outname`))
#run(pipeline(`echo $formatted` ,
# `pandoc -R -s --mathjax --self-contained --template
# $html_template -V wversion=$wversion -V wtime=$wtime -V wsource=$wsource
# -o $outname`))
cd(old_wd)
catch
cd(old_wd)
error("Unable to convert to html, check that you have pandoc installed and in your path")
end
end