no weird Base.run overload

pull/318/head
Shuhei Kadowaki 2020-05-09 02:31:45 +09:00
parent 14e7635458
commit e41202d3ff
5 changed files with 21 additions and 17 deletions

View File

@ -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,

View File

@ -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]

View File

@ -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 == "<pre class=\"julia-error\">\nERROR: ArgumentError: Package NonExisting not found in current path:\n- Run &#96;import Pkg; Pkg.add&#40;&quot;NonExisting&quot;&#41;&#96; to install the NonExisting package.\n\n</pre>\n"
@test doc3.chunks[2].rich_output == "<pre class=\"julia-error\">\nERROR: syntax: incomplete: premature end of input\n</pre>\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"

View File

@ -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 = "<pre class='hljl'>\n<span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-p'>[</span><span class='hljl-ni'>12</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-ni'>10</span><span class='hljl-p'>]</span><span class='hljl-t'>\n</span><span class='hljl-nf'>println</span><span class='hljl-p'>(</span><span class='hljl-n'>y</span><span class='hljl-p'>)</span>\n</pre>\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<div class=\"markdown\"><h3>Small markdown sample</h3>\n<p><strong>Hello</strong> from <code>code</code> block.</p>\n</div>"
@test doc.chunks[2].rich_output == "\n<div class=\"markdown\"><ul>\n<li><p>one</p>\n</li>\n<li><p>two</p>\n</li>\n<li><p>three</p>\n</li>\n</ul>\n</div>"
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))

View File

@ -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 = """