mirror of https://github.com/mpastell/Weave.jl
Fix `include_weave`. Closes #152.
parent
83e2e0ae20
commit
8194c8a1b8
|
@ -198,19 +198,19 @@ function notebook(source::String, out_path=:pwd, timeout=-1, nbconvert_options=[
|
|||
end
|
||||
|
||||
"""
|
||||
include_weave(doc, informat=:auto)
|
||||
include_weave(m::Module, doc, informat=:auto)
|
||||
|
||||
Include code from Weave document calling `include_string` on
|
||||
all code from doc. Code is run in the path of the include document.
|
||||
"""
|
||||
function include_weave(source, informat=:auto)
|
||||
function include_weave(m::Module, source, informat=:auto)
|
||||
old_path = pwd()
|
||||
doc = read_doc(source, informat)
|
||||
cd(doc.path)
|
||||
try
|
||||
code = join([x.content for x in
|
||||
filter(x -> isa(x,Weave.CodeChunk), doc.chunks)], "\n")
|
||||
include_string(code)
|
||||
include_string(m, code)
|
||||
catch e
|
||||
cd(old_path)
|
||||
throw(e)
|
||||
|
|
|
@ -0,0 +1,27 @@
|
|||
---
|
||||
title : Someheader
|
||||
---
|
||||
|
||||
```julia
|
||||
module Test1
|
||||
|
||||
x = 10
|
||||
y = 20
|
||||
|
||||
function testing(x)
|
||||
return x
|
||||
end
|
||||
|
||||
end
|
||||
```
|
||||
|
||||
Some random text in between
|
||||
|
||||
```julia
|
||||
module Test2
|
||||
|
||||
d = Dict("a" => "α")
|
||||
doc = read("header_test.jmd", String)
|
||||
|
||||
end
|
||||
```
|
|
@ -33,3 +33,10 @@ wdoc = weavestring(smod)
|
|||
sdoc = weavestring(smod, mod=:sandbox)
|
||||
@test occursin(r"Main.WeaveSandBox[0-9]*.TestMod\n", sdoc.chunks[1].output)
|
||||
@test sdoc.chunks[2].output == "x"
|
||||
|
||||
include_weave(Main, joinpath(@__DIR__, "documents/include_test.jmd"))
|
||||
@test Test1.x == 10
|
||||
@test Test1.y == 20
|
||||
@test Test1.testing("weave") == "weave"
|
||||
@test Test2.d["a"] == "α"
|
||||
@test split(Test2.doc, r"\r\n|\n")[1] == "---"
|
||||
|
|
Loading…
Reference in New Issue