From d3c3c01278db2bff4abc77d7fae5f265c3dd1a1c Mon Sep 17 00:00:00 2001 From: Jonas Isensee Date: Thu, 9 Apr 2020 11:42:48 +0200 Subject: [PATCH] add separate feature to suppress output as well Co-Authored-By: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com> --- src/readers.jl | 25 ++++++++++++++++++------- src/run.jl | 4 +++- 2 files changed, 21 insertions(+), 8 deletions(-) diff --git a/src/readers.jl b/src/readers.jl index 7ea0714e..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,17 +262,26 @@ 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[] - haskey(cell["metadata"], "jupyter") && get(cell["metadata"]["jupyter"], "source_hidden", false) && (push!(opt_strings, "echo = false")) + 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) 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())