Detect informat based on file extension

pull/35/head
Matti Pastell 2016-04-22 15:39:25 +03:00
parent 15f6f3b920
commit 42faaae5de
4 changed files with 22 additions and 6 deletions

View File

@ -23,7 +23,7 @@ ap = ArgParseSettings("Weave Julia documents using Weave.jl",
help = "output format"
"--informat"
arg_type = String
default = "noweb"
default = ":auto"
help = "output format"
"--out_path"
arg_type = String
@ -44,6 +44,11 @@ delete!(args, "source")
args_col = []
#Check for special values of out_path
if args["informat"] == ":auto"
args["informat"] = :auto
end
if args["out_path"] == ":doc"
args["out_path"] = :doc
elseif args["out_path"] == ":pwd"

View File

@ -55,7 +55,7 @@ Tangle source code from input document to .jl file.
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory,
`"somepath"`: Path as a AbstractString e.g `"/home/mpastell/weaveout"`
"""
function tangle(source ; out_path=:doc, informat="noweb")
function tangle(source ; out_path=:doc, informat=:auto)
doc = read_doc(source, informat)
cwd = get_cwd(doc, out_path)
@ -94,12 +94,12 @@ Weave an input document to output file.
**Note:** Run Weave from terminal and not using IJulia, Juno or ESS, they tend to mess with capturing output.
"""
function weave(source ; doctype = "pandoc", plotlib="Gadfly",
informat="noweb", out_path=:doc, fig_path = "figures", fig_ext = nothing,
informat=:auto, out_path=:doc, fig_path = "figures", fig_ext = nothing,
cache_path = "cache", cache=:off)
doc = read_doc(source, informat)
doc = run(doc, doctype = doctype, plotlib=plotlib,
informat = informat, out_path=out_path,
out_path=out_path,
fig_path = fig_path, fig_ext = fig_ext, cache_path = cache_path, cache=cache)
formatted = format(doc)

View File

@ -25,9 +25,20 @@ const input_formats = Dict{AbstractString, Any}(
r"(^#\+)|(^#%%\+)|(^# %%\+)")
)
"""Detect the input format based on file extension"""
function detect_informat(source::AbstractString)
ext = lowercase(splitext(source)[2])
ext == ".jl" && return "script"
ext == ".jmd" && return "markdown"
return "noweb"
end
"""Read and parse input document"""
function read_doc(source::AbstractString, format="noweb"::AbstractString)
function read_doc(source::AbstractString, format=:auto)
format == :auto && (format = detect_informat(source))
document = @compat readstring(source)
parsed = parse_doc(document, format)
doc = WeaveDoc(source, parsed)

View File

@ -18,7 +18,7 @@ Run code chunks and capture output from parsed document.
**Note:** Run command from terminal and not using IJulia, Juno or ESS, they tend to mess with capturing output.
"""
function Base.run(doc::WeaveDoc; doctype = "pandoc", plotlib="Gadfly", informat="noweb",
function Base.run(doc::WeaveDoc; doctype = "pandoc", plotlib="Gadfly",
out_path=:doc, fig_path = "figures", fig_ext = nothing,
cache_path = "cache", cache = :off)
#cache :all, :user, :off, :refresh