rm header_args

pull/325/head
Shuhei Kadowaki 2020-05-10 15:23:24 +09:00
parent 2c7f3da7cc
commit bc0f687352
2 changed files with 36 additions and 93 deletions

View File

@ -116,39 +116,41 @@ function weave(
)
doc = WeaveDoc(source, informat)
isnothing(doctype) && (doctype = detect_doctype(doc.source))
doc.doctype = doctype
# Read args from document header, overrides command line args
if haskey(doc.header, WEAVE_OPTION_NAME)
(
doctype,
informat,
out_path,
args,
fig_path,
fig_ext,
cache_path,
cache,
throw_errors,
template,
highlight_theme,
css,
pandoc_options,
latex_cmd,
) = header_args(
doc,
out_path,
fig_ext,
fig_path,
cache_path,
cache,
throw_errors,
template,
highlight_theme,
css,
pandoc_options,
latex_cmd,
)
# overwrites given options with header options, which have more precedence
# NOTE:
# - support format specific option specification
# - fix paths relative to `source`
weave_options = get(doc.header, WEAVE_OPTION_NAME, Dict())
if !isempty(weave_options)
doctype = get(weave_options, "doctype", doctype)
weave_options = combine_args(weave_options, doctype)
if haskey(weave_options, "out_path")
out_path = let
out_path = weave_options["out_path"]
if out_path == ":doc" || out_path == ":pwd"
Symbol(out_path)
else
joinpath(dirname(source), out_path)
end
end
end
mod = get(weave_options, "mod", mod)
mod isa AbstractString && (mod = Main.eval(Meta.parse(mod)))
fig_path = get(weave_options, "fig_path", fig_path)
fig_ext = get(weave_options, "fig_ext", fig_ext)
cache_path = get(weave_options, "cache_path", cache_path)
cache = Symbol(get(weave_options, "cache", cache))
throw_errors = get(weave_options, "throw_errors", throw_errors)
if haskey(weave_options, "template")
template = weave_options["template"]
template isa AbstractString && (template = joinpath(dirname(source), template))
end
highlight_theme = get(weave_options, "highlight_theme", highlight_theme)
css = get(weave_options, "css", css)
pandoc_options = get(weave_options, "pandoc_options", pandoc_options)
latex_cmd = get(weave_options, "latex_cmd", latex_cmd)
latex_keep_unicode = get(weave_options, "latex_cmd", latex_keep_unicode)
end
isnothing(template) || (doc.template = template)
@ -169,13 +171,12 @@ function weave(
throw_errors = throw_errors,
latex_keep_unicode = latex_keep_unicode,
)
formatted = format(doc)
outname = get_outname(out_path, doc)
open(outname, "w") do io
write(io, formatted)
end
open(io->write(io,formatted), outname, "w")
# Special for that need external programs
if doc.doctype == "pandoc2html"

View File

@ -77,61 +77,3 @@ function combine_args(args, doctype)
haskey(specific, doctype) && merge!(common, specific[doctype])
common
end
"""
header_args(doc::WeaveDoc)
Get weave arguments from document header.
"""
function header_args(
doc::WeaveDoc,
out_path,
fig_ext,
fig_path,
cache_path,
cache,
throw_errors,
template,
highlight_theme,
css,
pandoc_options,
latex_cmd,
)
args = get(doc.header, WEAVE_OPTION_NAME, Dict())
doctype = get(args, "doctype", doc.doctype)
args = combine_args(args, doctype)
informat = get(args, "informat", nothing)
out_path = get(args, "out_path", out_path)
out_path == ":pwd" && (out_path = :pwd)
isa(out_path, Symbol) || (out_path = joinpath(dirname(doc.source), out_path))
fig_path = get(args, "fig_path", fig_path)
fig_ext = get(args, "fig_ext", fig_ext)
cache_path = get(args, "cache_path", cache_path)
cache = Symbol(get(args, "cache", cache))
throw_errors = get(args, "throw_errors", throw_errors)
template = get(args, "template", template)
if template != nothing && !isa(template, Mustache.MustacheTokens) && !isempty(template)
template = joinpath(dirname(doc.source), template)
end
highlight_theme = get(args, "highlight_theme", highlight_theme)
css = get(args, "css", css)
pandoc_options = get(args, "pandoc_options", pandoc_options)
latex_cmd = get(args, "latex_cmd", latex_cmd)
return (
doctype,
informat,
out_path,
args,
fig_path,
fig_ext,
cache_path,
cache,
throw_errors,
template,
highlight_theme,
css,
pandoc_options,
latex_cmd,
)
end