Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
29 changes: 21 additions & 8 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,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
Expand All @@ -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
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