`WEAVE_OPTION_NAME`

pull/319/head
Shuhei Kadowaki 2020-05-09 22:42:05 +09:00
parent 36bdd4f82b
commit 4dae2a0816
5 changed files with 8 additions and 8 deletions

View File

@ -4,7 +4,7 @@ using Mustache
using Requires using Requires
const WEAVE_OPTION = "options" # TODO: rename to "weave_options" const WEAVE_OPTION_NAME = "options" # TODO: rename to "weave_options"
function __init__() function __init__()
@require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Base.include( @require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Base.include(
@ -126,7 +126,7 @@ function weave(
doc.doctype = doctype doc.doctype = doctype
# Read args from document header, overrides command line args # Read args from document header, overrides command line args
if haskey(doc.header, "options") if haskey(doc.header, WEAVE_OPTION_NAME)
( (
doctype, doctype,
informat, informat,

View File

@ -107,7 +107,7 @@ function header_args(
pandoc_options, pandoc_options,
latex_cmd, latex_cmd,
) )
args = get(doc.header, "options", Dict()) args = get(doc.header, WEAVE_OPTION_NAME, Dict())
doctype = get(args, "doctype", doc.doctype) doctype = get(args, "doctype", doc.doctype)
args = combine_args(args, doctype) args = combine_args(args, doctype)
informat = get(args, "informat", :auto) informat = get(args, "informat", :auto)

View File

@ -131,7 +131,7 @@ function strip_header!(docchunk::DocChunk, doctype)
else else
# only strips Weave headers # only strips Weave headers
header = YAML.load(m[:header]) header = YAML.load(m[:header])
delete!(header, "options") delete!(header, WEAVE_OPTION_NAME)
if isempty(header) if isempty(header)
lstrip(replace(content, HEADER_REGEX => "")) lstrip(replace(content, HEADER_REGEX => ""))
else else

View File

@ -20,9 +20,9 @@ function WeaveDoc(source, chunks)
header = parse_header(first(chunks)) header = parse_header(first(chunks))
# get chunk defaults from header and update # get chunk defaults from header and update
chunk_defaults = deepcopy(rcParams[:chunk_defaults]) chunk_defaults = deepcopy(rcParams[:chunk_defaults])
if haskey(header, WEAVE_OPTION) if haskey(header, WEAVE_OPTION_NAME)
for key in keys(chunk_defaults) for key in keys(chunk_defaults)
if (val = get(header[WEAVE_OPTION], string(key), nothing)) !== nothing if (val = get(header[WEAVE_OPTION_NAME], string(key), nothing)) !== nothing
chunk_defaults[key] = val chunk_defaults[key] = val
end end
end end

View File

@ -1,4 +1,4 @@
using YAML using Weave.YAML
# TODO: # TODO:
# - header stripping # - header stripping
@ -19,7 +19,7 @@ options:
--- ---
""") """)
let args = header["options"] let args = header[Weave.WEAVE_OPTION_NAME]
@test Weave.combine_args(args, "md2html") == Dict("fig_ext" => ".png", "out_path" => "html/") @test Weave.combine_args(args, "md2html") == Dict("fig_ext" => ".png", "out_path" => "html/")
@test Weave.combine_args(args, "github") == Dict("fig_ext" => ".png", "out_path" => "md/") @test Weave.combine_args(args, "github") == Dict("fig_ext" => ".png", "out_path" => "md/")
@test Weave.combine_args(args, "pandoc") == Dict("fig_ext" => ".png", "out_path" => "reports") @test Weave.combine_args(args, "pandoc") == Dict("fig_ext" => ".png", "out_path" => "reports")