Skip to content

Commit

Permalink
add separate feature to suppress output as well
Browse files Browse the repository at this point in the history
Co-Authored-By: Shuhei Kadowaki <[email protected]>
  • Loading branch information
JonasIsensee and aviatesk committed Apr 9, 2020
1 parent 4fb4239 commit e2057f6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/config.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ const defaultParams =
:doc_number => 0,
:chunk_defaults =>
Dict{Symbol,Any}(
:suppress_output=> false,
:echo=> true,
:results=> "markup",
:hold => false,
Expand Down
25 changes: 18 additions & 7 deletions src/readers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 3 additions & 1 deletion src/run.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand Down

0 comments on commit e2057f6

Please sign in to comment.