diff --git a/src/Weave.jl b/src/Weave.jl index 2020de0..f78bd86 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -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) diff --git a/test/documents/include_test.jmd b/test/documents/include_test.jmd new file mode 100644 index 0000000..911903b --- /dev/null +++ b/test/documents/include_test.jmd @@ -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 +``` diff --git a/test/sandbox_test.jl b/test/sandbox_test.jl index 0ecf754..a68a10e 100644 --- a/test/sandbox_test.jl +++ b/test/sandbox_test.jl @@ -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] == "---"