Skip to content

Commit e2057f6

Browse files
add separate feature to suppress output as well
Co-Authored-By: Shuhei Kadowaki <[email protected]>
1 parent 4fb4239 commit e2057f6

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/config.jl

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const defaultParams =
66
:doc_number => 0,
77
:chunk_defaults =>
88
Dict{Symbol,Any}(
9+
:suppress_output=> false,
910
:echo=> true,
1011
:results=> "markup",
1112
:hold => false,

src/readers.jl

+18-7
Original file line numberDiff line numberDiff line change
@@ -102,14 +102,16 @@ function parse_doc(document::AbstractString, format::MarkupInput)
102102
if m.captures[1] == nothing
103103
optionString = ""
104104
else
105-
optionString=strip(m.captures[1])
105+
optionString= m.captures[1]
106106
end
107107

108108
options = Dict{Symbol,Any}()
109-
if length(optionString) > 0
110-
expr = Meta.parse(optionString)
111-
Base.Meta.isexpr(expr,:(=)) && (options[expr.args[1]] = expr.args[2])
112-
Base.Meta.isexpr(expr,:toplevel) && map(pushopt,fill(options,length(expr.args)),expr.args)
109+
if !isempty(optionString)
110+
map(strip.(split(optionString, ','))) do opt
111+
expr = Meta.parse(opt)
112+
Base.Meta.isexpr(expr,:(=)) && (options[expr.args[1]] = expr.args[2])
113+
Base.Meta.isexpr(expr,:toplevel) && map(pushopt,fill(options,length(expr.args)),expr.args)
114+
end
113115
end
114116
haskey(options, :label) && (options[:name] = options[:label])
115117
haskey(options, :name) || (options[:name] = nothing)
@@ -260,17 +262,26 @@ function parse_doc(document::String, format::NotebookInput)
260262
document = replace(document, "\r\n" => "\n")
261263
nb = JSON.parse(document)
262264
parsed = Any[]
263-
options = Dict{Symbol,Any}()
264265
opt_string = ""
265266
docno = 1
266267
codeno = 1
267268

268269
for cell in nb["cells"]
269270
srctext = "\n" * join(cell["source"], "")
271+
options = Dict{Symbol,Any}()
270272

271273
if cell["cell_type"] == "code"
272274
opt_strings = String[]
273-
haskey(cell["metadata"], "jupyter") && get(cell["metadata"]["jupyter"], "source_hidden", false) && (push!(opt_strings, "echo = false"))
275+
if haskey(cell["metadata"], "jupyter")
276+
if get(cell["metadata"]["jupyter"], "source_hidden", false)
277+
push!(opt_strings, "echo = false")
278+
options[:echo] = false
279+
end
280+
if get(cell["metadata"]["jupyter"], "outputs_hidden", false)
281+
push!(opt_strings, "suppress_output = true")
282+
options[:suppress_output] = true
283+
end
284+
end
274285
opt_string = join(opt_strings, ", ")
275286
chunk = CodeChunk(rstrip(srctext), codeno, 0, opt_string, options)
276287
push!(parsed, chunk)

src/run.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -315,7 +315,9 @@ function eval_chunk(chunk::CodeChunk, report::Report, SandBox::Module)
315315
chunk = Base.invokelatest(hook, chunk)
316316
end
317317

318-
if chunk.options[:term]
318+
if chunk.options[:suppress_output]
319+
chunks = CodeChunk[]
320+
elseif chunk.options[:term]
319321
chunks = collect_results(chunk, TermResult())
320322
elseif chunk.options[:hold]
321323
chunks = collect_results(chunk, CollectResult())

0 commit comments

Comments
 (0)