mirror of https://github.com/mpastell/Weave.jl
commit
fd07d2db3f
50
src/Weave.jl
50
src/Weave.jl
|
@ -59,9 +59,9 @@ function tangle(
|
|||
doc = WeaveDoc(source, informat)
|
||||
doc.cwd = get_cwd(doc, out_path)
|
||||
|
||||
outname = get_outname(out_path, doc, ext = "jl")
|
||||
out_path = get_out_path(doc, out_path, "jl")
|
||||
|
||||
open(outname, "w") do io
|
||||
open(out_path, "w") do io
|
||||
for chunk in doc.chunks
|
||||
if typeof(chunk) == CodeChunk
|
||||
options = merge(doc.chunk_defaults, chunk.options)
|
||||
|
@ -69,8 +69,8 @@ function tangle(
|
|||
end
|
||||
end
|
||||
end
|
||||
doc.cwd == pwd() && (outname = basename(outname))
|
||||
@info("Writing to file $outname")
|
||||
|
||||
@info "Tangled to $(out_path)"
|
||||
end
|
||||
|
||||
"""
|
||||
|
@ -198,8 +198,8 @@ function weave(
|
|||
set_rendering_options!(doc; template = template, highlight_theme = highlight_theme, css = css, keep_unicode = keep_unicode)
|
||||
rendered = render_doc(doc)
|
||||
|
||||
outname = get_outname(out_path, doc)
|
||||
open(io->write(io,rendered), outname, "w")
|
||||
out_path = get_out_path(doc, out_path)
|
||||
write(out_path, rendered)
|
||||
|
||||
# document generation via external programs
|
||||
# -----------------------------------------
|
||||
|
@ -210,23 +210,22 @@ function weave(
|
|||
|
||||
doctype = doc.doctype
|
||||
if doctype == "pandoc2html"
|
||||
mdname = outname
|
||||
outname = get_outname(out_path, doc, ext = "html")
|
||||
pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options)
|
||||
rm(mdname)
|
||||
intermediate = out_path
|
||||
out_path = get_out_path(doc, out_path, "html")
|
||||
pandoc2html(rendered, doc, highlight_theme, out_path, pandoc_options)
|
||||
rm(intermediate)
|
||||
elseif doctype == "pandoc2pdf"
|
||||
mdname = outname
|
||||
outname = get_outname(out_path, doc, ext = "pdf")
|
||||
pandoc2pdf(rendered, doc, outname, pandoc_options)
|
||||
rm(mdname)
|
||||
intermediate = out_path
|
||||
out_path = get_out_path(doc, out_path, "pdf")
|
||||
pandoc2pdf(rendered, doc, out_path, pandoc_options)
|
||||
rm(intermediate)
|
||||
elseif doctype == "md2pdf"
|
||||
run_latex(doc, outname, latex_cmd)
|
||||
outname = get_outname(out_path, doc, ext = "pdf")
|
||||
run_latex(doc, out_path, latex_cmd)
|
||||
out_path = get_out_path(doc, out_path, ext = "pdf")
|
||||
end
|
||||
|
||||
doc.cwd == pwd() && (outname = basename(outname))
|
||||
@info "Report weaved to $outname"
|
||||
return abspath(outname)
|
||||
@info "Weaved to $(out_path)"
|
||||
return out_path
|
||||
end
|
||||
|
||||
weave(doc::AbstractString, doctype::Union{Symbol,AbstractString}; kwargs...) =
|
||||
|
@ -242,6 +241,9 @@ function specific_options!(weave_options, doctype)
|
|||
end
|
||||
end
|
||||
|
||||
get_out_path(doc, out_path, ext::Nothing = nothing) = get_out_path(doc, out_path, doc.format.extension)
|
||||
get_out_path(doc, out_path, ext) = abspath(get_cwd(doc, out_path), string(doc.basename , '.', ext))
|
||||
|
||||
"""
|
||||
notebook(source::AbstractString; kwargs...)
|
||||
|
||||
|
@ -277,15 +279,13 @@ function notebook(
|
|||
doc = WeaveDoc(source)
|
||||
converted = convert_to_notebook(doc)
|
||||
doc.cwd = get_cwd(doc, out_path)
|
||||
outfile = get_outname(out_path, doc, ext = "ipynb")
|
||||
out_path = get_out_path(doc, out_path, "ipynb")
|
||||
|
||||
open(outfile, "w") do f
|
||||
write(f, converted)
|
||||
end
|
||||
write(out_path, converted)
|
||||
|
||||
@info "Running nbconvert"
|
||||
@info "Running nbconvert ..."
|
||||
return read(
|
||||
`$jupyter_path nbconvert --ExecutePreprocessor.timeout=$timeout --to notebook --execute $outfile $nbconvert_options --output $outfile`,
|
||||
`$jupyter_path nbconvert --ExecutePreprocessor.timeout=$timeout --to notebook --execute $(out_path) $nbconvert_options --output $(out_path)`,
|
||||
String,
|
||||
)
|
||||
end
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
function pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options)
|
||||
function pandoc2html(rendered, doc, highlight_theme, out_path, pandoc_options)
|
||||
template_path = normpath(TEMPLATE_DIR, "pandoc2html.html")
|
||||
stylesheet_path = normpath(STYLESHEET_DIR, "pandoc2html_skeleton.css")
|
||||
highlight_stylesheet = get_highlight_stylesheet(MIME("text/html"), highlight_theme)
|
||||
|
@ -21,7 +21,7 @@ function pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options)
|
|||
# Change path for pandoc
|
||||
cd_back = let d = pwd(); () -> cd(d); end
|
||||
cd(doc.cwd)
|
||||
outname = basename(outname)
|
||||
out_path = basename(out_path)
|
||||
|
||||
try
|
||||
cmd = `pandoc -f markdown+raw_html -s --mathjax=""
|
||||
|
@ -34,7 +34,7 @@ function pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options)
|
|||
-V weave_date=$weave_date
|
||||
-V weave_source=$weave_source
|
||||
-V headerscript=$header_script
|
||||
-o $outname`
|
||||
-o $out_path`
|
||||
proc = open(cmd, "r+")
|
||||
println(proc.in, rendered)
|
||||
close(proc.in)
|
||||
|
@ -47,10 +47,10 @@ function pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options)
|
|||
end
|
||||
end
|
||||
|
||||
function pandoc2pdf(rendered, doc, outname, pandoc_options)
|
||||
function pandoc2pdf(rendered, doc, out_path, pandoc_options)
|
||||
header_template = normpath(TEMPLATE_DIR, "pandoc2pdf_header.txt")
|
||||
|
||||
outname = basename(outname)
|
||||
out_path = basename(out_path)
|
||||
|
||||
# Change path for pandoc
|
||||
cd_back = let d = pwd(); () -> cd(d); end
|
||||
|
@ -69,7 +69,7 @@ function pandoc2pdf(rendered, doc, outname, pandoc_options)
|
|||
cmd = `pandoc -f markdown+raw_tex -s --pdf-engine=xelatex --highlight-style=tango
|
||||
$filt $citeproc $pandoc_options
|
||||
--include-in-header=$header_template
|
||||
-V fontsize=12pt -o $outname`
|
||||
-V fontsize=12pt -o $out_path`
|
||||
proc = open(cmd, "r+")
|
||||
println(proc.in, rendered)
|
||||
close(proc.in)
|
||||
|
@ -82,12 +82,12 @@ function pandoc2pdf(rendered, doc, outname, pandoc_options)
|
|||
end
|
||||
end
|
||||
|
||||
function run_latex(doc::WeaveDoc, outname, latex_cmd = "xelatex")
|
||||
function run_latex(doc::WeaveDoc, out_path, latex_cmd = "xelatex")
|
||||
cd_back = let d = pwd(); () -> cd(d); end
|
||||
cd(doc.cwd)
|
||||
|
||||
xname = basename(outname)
|
||||
@info "Weaved code to $outname . Running $latex_cmd" # space before '.' added for link to be clickable in Juno terminal
|
||||
xname = basename(out_path)
|
||||
@info "Weaved code to $out_path . Running $latex_cmd" # space before '.' added for link to be clickable in Juno terminal
|
||||
textmp = mktempdir(".")
|
||||
try
|
||||
cmd = `$latex_cmd -shell-escape $xname -aux-directory $textmp -include-directory $(doc.cwd)`
|
||||
|
|
17
src/run.jl
17
src/run.jl
|
@ -344,23 +344,6 @@ function get_figname(report::Report, chunk; fignum = nothing, ext = nothing)
|
|||
return full_name, rel_name
|
||||
end
|
||||
|
||||
"""Get output file name based on out_path"""
|
||||
function get_outname(out_path::Symbol, doc::WeaveDoc; ext = nothing)
|
||||
isnothing(ext) && (ext = doc.format.extension)
|
||||
outname = "$(doc.cwd)/$(doc.basename).$ext"
|
||||
end
|
||||
|
||||
"""Get output file name based on out_path"""
|
||||
function get_outname(out_path::AbstractString, doc::WeaveDoc; ext = nothing)
|
||||
isnothing(ext) && (ext = doc.format.extension)
|
||||
splitted = splitext(out_path)
|
||||
if (splitted[2]) == ""
|
||||
outname = "$(doc.cwd)/$(doc.basename).$ext"
|
||||
else
|
||||
outname = expanduser(out_path)
|
||||
end
|
||||
end
|
||||
|
||||
function set_rc_params(doc::WeaveDoc, fig_path, fig_ext)
|
||||
if isnothing(fig_ext)
|
||||
doc.chunk_defaults[:fig_ext] = doc.format.fig_ext
|
||||
|
|
Loading…
Reference in New Issue