diff --git a/src/Weave.jl b/src/Weave.jl index 06c79a4..f8a0773 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -152,12 +152,12 @@ function weave( ) end - template != nothing && (doc.template = template) - highlight_theme != nothing && (doc.highlight_theme = highlight_theme) + template !== nothing && (doc.template = template) + highlight_theme !== nothing && (doc.highlight_theme = highlight_theme) # theme != nothing && (doc.theme = theme) # Reserved for themes - css != nothing && (doc.css = css) + css !== nothing && (doc.css = css) - doc = run( + doc = run_doc( doc, doctype = doctype, mod = mod, diff --git a/src/run.jl b/src/run.jl index d68476d..d65d9f2 100644 --- a/src/run.jl +++ b/src/run.jl @@ -1,7 +1,7 @@ using Base64 """ - run(doc::WeaveDoc; kwargs...) + run_doc(doc::WeaveDoc; kwargs...) Run code chunks and capture output from the parsed document. @@ -28,7 +28,7 @@ Run code chunks and capture output from the parsed document. !!! note Run Weave from terminal and try to avoid weaving from IJulia or ESS; they tend to mess with capturing output. """ -function Base.run( +function run_doc( doc::WeaveDoc; doctype::Union{Symbol,AbstractString} = :auto, out_path::Union{Symbol,AbstractString} = :doc, @@ -44,6 +44,7 @@ function Base.run( # cache :all, :user, :off, :refresh doc.cwd = get_cwd(doc, out_path) + # doctype detection is unnecessary here, but existing unit test requires this. doctype == :auto && (doctype = detect_doctype(doc.source)) doc.doctype = doctype doc.format = formats[doctype] diff --git a/test/errors_test.jl b/test/errors_test.jl index f973da3..c0d4162 100644 --- a/test/errors_test.jl +++ b/test/errors_test.jl @@ -1,4 +1,5 @@ using Weave +using Weave: run_doc using Test s1= """ @@ -22,7 +23,7 @@ print(y p1 = Weave.parse_doc(s1, "markdown") doc = Weave.WeaveDoc("dummy1.jmd", p1, Dict()) -doc1 = Weave.run(doc, doctype = "pandoc") +doc1 = run_doc(doc, doctype = "pandoc") doc1.chunks[1].output @@ -30,10 +31,10 @@ doc1.chunks[1].output @test doc1.chunks[2].output == "Error: syntax: incomplete: premature end of input\n" @test doc1.chunks[3].output == "\njulia> plot(x)\nError: UndefVarError: plot not defined\n\njulia> y = 10\n10\n\njulia> print(y\nError: syntax: incomplete: premature end of input\n" -@test_throws ArgumentError Weave.run(doc, doctype = "pandoc", throw_errors = true) +@test_throws ArgumentError run_doc(doc, doctype = "pandoc", throw_errors = true) doc = Weave.WeaveDoc("dummy1.jmd", p1, Dict()) -doc3 = Weave.run(doc, doctype = "md2html") +doc3 = run_doc(doc, doctype = "md2html") @test doc3.chunks[1].rich_output == "
\nERROR: ArgumentError: Package NonExisting not found in current path:\n- Run `import Pkg; Pkg.add("NonExisting")` to install the NonExisting package.\n\n
\n" @test doc3.chunks[2].rich_output == "
\nERROR: syntax: incomplete: premature end of input\n
\n" @test doc3.chunks[3].output == "\njulia> plot(x)\nError: UndefVarError: plot not defined\n\njulia> y = 10\n10\n\njulia> print(y\nError: syntax: incomplete: premature end of input\n" diff --git a/test/formatter_test.jl b/test/formatter_test.jl index acf4de1..e2b559c 100644 --- a/test/formatter_test.jl +++ b/test/formatter_test.jl @@ -1,4 +1,5 @@ using Weave +using Weave: run_doc using Test # Test rendering of doc chunks @@ -22,7 +23,7 @@ f = Weave.format_chunk(dchunk, docformat.formatdict, docformat) # Test with actual doc parsed = Weave.read_doc("documents/chunk_options.noweb") -doc = Weave.run(parsed, doctype = "md2html") +doc = run_doc(parsed, doctype = "md2html") c_check = "
\nx = [12, 10]\nprintln(y)\n
\n" doc.format.formatdict[:theme] = doc.highlight_theme @@ -39,7 +40,7 @@ rendered = Weave.render_doc("Hello", doc, doc.format) # Tex format parsed = Weave.read_doc("documents/chunk_options.noweb") -doc = Weave.run(parsed, doctype = "md2tex") +doc = run_doc(parsed, doctype = "md2tex") c_check = "\\begin{lstlisting}\n(*@\\HLJLnf{println}@*)(*@\\HLJLp{(}@*)(*@\\HLJLn{x}@*)(*@\\HLJLp{)}@*)\n\\end{lstlisting}\n" doc.format.formatdict[:theme] = doc.highlight_theme @@ -101,15 +102,15 @@ tfied = "\\ensuremath{\\bm{\\mathrm{L}}} \\ensuremath{\\bm{\\mathfrak{F}}} \\ens # Test markdown output from chunks parsed = Weave.read_doc("documents/markdown_output.jmd") -doc = Weave.run(parsed, doctype = "md2html") +doc = run_doc(parsed, doctype = "md2html") @test doc.chunks[1].rich_output == "\n

Small markdown sample

\n

Hello from code block.

\n
" @test doc.chunks[2].rich_output == "\n
\n
" -ldoc = Weave.run(parsed, doctype = "md2tex") +ldoc = run_doc(parsed, doctype = "md2tex") @test ldoc.chunks[1].rich_output == "\n\\subsubsection{Small markdown sample}\n\\textbf{Hello} from \\texttt{code} block.\n\n" @test ldoc.chunks[2].rich_output == "\n\\begin{itemize}\n\\item one\n\n\n\\item two\n\n\n\\item three\n\n\\end{itemize}\n" -mdoc = Weave.run(parsed, doctype = "github") +mdoc = run_doc(parsed, doctype = "github") @test mdoc.chunks[1].rich_output == "\n\n### Small markdown sample\n\n**Hello** from `code` block.\n\n" @test mdoc.chunks[2].rich_output == "\n\n* one\n* two\n* three\n\n" @@ -143,11 +144,11 @@ doc_content = """ """ parsed = doc_from_string(doc_content) -ldoc = Weave.run(parsed, doctype = "md2tex") +ldoc = run_doc(parsed, doctype = "md2tex") @test occursin(Weave.uc2tex("α"),Weave.format(ldoc)) @test !occursin("α",Weave.format(ldoc)) parsed = doc_from_string(doc_content) -ldoc = Weave.run(parsed, doctype = "md2tex",latex_keep_unicode=true) +ldoc = run_doc(parsed, doctype = "md2tex",latex_keep_unicode=true) @test occursin("α",Weave.format(ldoc)) @test !occursin(Weave.uc2tex("α"),Weave.format(ldoc)) diff --git a/test/sandbox_test.jl b/test/sandbox_test.jl index a68a10e..365c97f 100644 --- a/test/sandbox_test.jl +++ b/test/sandbox_test.jl @@ -1,10 +1,11 @@ using Weave +using Weave: run_doc using Test function weavestring(source; doctype = "pandoc", informat="markdown", mod=Main) p1 = Weave.parse_doc(source, informat) doc = Weave.WeaveDoc("dummy1.jmd", p1, Dict()) - return Weave.run(doc, doctype=doctype, mod=mod) + return run_doc(doc, doctype=doctype, mod=mod) end smod = """