From 4dae2a08169f3b6c1319acd20369c86775efe26c Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Sat, 9 May 2020 22:42:05 +0900 Subject: [PATCH] `WEAVE_OPTION_NAME` --- src/Weave.jl | 4 ++-- src/config.jl | 2 +- src/format.jl | 2 +- src/reader/reader.jl | 4 ++-- test/test_header.jl | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Weave.jl b/src/Weave.jl index 70ab2a5..561fd5f 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -4,7 +4,7 @@ using Mustache using Requires -const WEAVE_OPTION = "options" # TODO: rename to "weave_options" +const WEAVE_OPTION_NAME = "options" # TODO: rename to "weave_options" function __init__() @require Plots = "91a5bcdd-55d7-5caf-9e0b-520d859cae80" Base.include( @@ -126,7 +126,7 @@ function weave( doc.doctype = doctype # Read args from document header, overrides command line args - if haskey(doc.header, "options") + if haskey(doc.header, WEAVE_OPTION_NAME) ( doctype, informat, diff --git a/src/config.jl b/src/config.jl index d4129d0..2d82ef3 100644 --- a/src/config.jl +++ b/src/config.jl @@ -107,7 +107,7 @@ function header_args( pandoc_options, latex_cmd, ) - args = get(doc.header, "options", Dict()) + args = get(doc.header, WEAVE_OPTION_NAME, Dict()) doctype = get(args, "doctype", doc.doctype) args = combine_args(args, doctype) informat = get(args, "informat", :auto) diff --git a/src/format.jl b/src/format.jl index f9887da..3bb7117 100644 --- a/src/format.jl +++ b/src/format.jl @@ -131,7 +131,7 @@ function strip_header!(docchunk::DocChunk, doctype) else # only strips Weave headers header = YAML.load(m[:header]) - delete!(header, "options") + delete!(header, WEAVE_OPTION_NAME) if isempty(header) lstrip(replace(content, HEADER_REGEX => "")) else diff --git a/src/reader/reader.jl b/src/reader/reader.jl index 1f75c3c..d8b2199 100644 --- a/src/reader/reader.jl +++ b/src/reader/reader.jl @@ -20,9 +20,9 @@ function WeaveDoc(source, chunks) header = parse_header(first(chunks)) # get chunk defaults from header and update chunk_defaults = deepcopy(rcParams[:chunk_defaults]) - if haskey(header, WEAVE_OPTION) + if haskey(header, WEAVE_OPTION_NAME) 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 end end diff --git a/test/test_header.jl b/test/test_header.jl index 361061c..4b20206 100644 --- a/test/test_header.jl +++ b/test/test_header.jl @@ -1,4 +1,4 @@ -using YAML +using Weave.YAML # TODO: # - 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, "github") == Dict("fig_ext" => ".png", "out_path" => "md/") @test Weave.combine_args(args, "pandoc") == Dict("fig_ext" => ".png", "out_path" => "reports")