diff --git a/src/config.jl b/src/config.jl index 7875dacc..1a57bfc7 100644 --- a/src/config.jl +++ b/src/config.jl @@ -6,6 +6,7 @@ const defaultParams = :doc_number => 0, :chunk_defaults => Dict{Symbol,Any}( + :suppress_output=> false, :echo=> true, :results=> "markup", :hold => false, diff --git a/src/readers.jl b/src/readers.jl index 47446986..6059c536 100644 --- a/src/readers.jl +++ b/src/readers.jl @@ -102,14 +102,16 @@ function parse_doc(document::AbstractString, format::MarkupInput) if m.captures[1] == nothing optionString = "" else - optionString=strip(m.captures[1]) + optionString= m.captures[1] end options = Dict{Symbol,Any}() - if length(optionString) > 0 - expr = Meta.parse(optionString) - Base.Meta.isexpr(expr,:(=)) && (options[expr.args[1]] = expr.args[2]) - Base.Meta.isexpr(expr,:toplevel) && map(pushopt,fill(options,length(expr.args)),expr.args) + if !isempty(optionString) + map(strip.(split(optionString, ','))) do opt + expr = Meta.parse(opt) + Base.Meta.isexpr(expr,:(=)) && (options[expr.args[1]] = expr.args[2]) + Base.Meta.isexpr(expr,:toplevel) && map(pushopt,fill(options,length(expr.args)),expr.args) + end end haskey(options, :label) && (options[:name] = options[:label]) haskey(options, :name) || (options[:name] = nothing) @@ -260,15 +262,27 @@ function parse_doc(document::String, format::NotebookInput) document = replace(document, "\r\n" => "\n") nb = JSON.parse(document) parsed = Any[] - options = Dict{Symbol,Any}() opt_string = "" docno = 1 codeno = 1 for cell in nb["cells"] srctext = "\n" * join(cell["source"], "") + options = Dict{Symbol,Any}() if cell["cell_type"] == "code" + opt_strings = String[] + if haskey(cell["metadata"], "jupyter") + if get(cell["metadata"]["jupyter"], "source_hidden", false) + push!(opt_strings, "echo = false") + options[:echo] = false + end + if get(cell["metadata"]["jupyter"], "outputs_hidden", false) + push!(opt_strings, "suppress_output = true") + options[:suppress_output] = true + end + end + opt_string = join(opt_strings, ", ") chunk = CodeChunk(rstrip(srctext), codeno, 0, opt_string, options) push!(parsed, chunk) codeno += 1 @@ -278,8 +292,7 @@ function parse_doc(document::String, format::NotebookInput) docno +=1 end end - -return parsed + return parsed end #Use this if regex is undefined diff --git a/src/run.jl b/src/run.jl index 52bd7d8a..1a504bd0 100644 --- a/src/run.jl +++ b/src/run.jl @@ -315,7 +315,9 @@ function eval_chunk(chunk::CodeChunk, report::Report, SandBox::Module) chunk = Base.invokelatest(hook, chunk) end - if chunk.options[:term] + if chunk.options[:suppress_output] + chunks = CodeChunk[] + elseif chunk.options[:term] chunks = collect_results(chunk, TermResult()) elseif chunk.options[:hold] chunks = collect_results(chunk, CollectResult())