From 888b732f86136f25be152d3c3e42a61d133aa3dc Mon Sep 17 00:00:00 2001 From: Matti Pastell Date: Mon, 13 Mar 2017 15:05:07 +0200 Subject: [PATCH] Fix output for `term=true`. Closes #82. --- src/chunks.jl | 2 +- src/display_methods.jl | 2 +- src/format.jl | 4 ++-- src/readers.jl | 8 +++----- test/documents/chunk_options.noweb | 6 ++++++ test/documents/chunk_options_ref.md | 22 +++++++++++++++++++++- test/documents/tangle/chunk_options.jl.ref | 16 +++++++++++++++- test/documents/test_hold_ref.md | 12 +++++++----- 8 files changed, 56 insertions(+), 16 deletions(-) diff --git a/src/chunks.jl b/src/chunks.jl index 1e4a303..b3f05f2 100644 --- a/src/chunks.jl +++ b/src/chunks.jl @@ -45,7 +45,7 @@ type CodeChunk <: WeaveChunk figures::Array{AbstractString} result::Array{ChunkOutput} function CodeChunk(content, number, start_line, optionstring, options) - new(rstrip(content), number, 0, start_line, optionstring, options, "","", AbstractString[], ChunkOutput[]) + new(rstrip(content) * "\n", number, 0, start_line, optionstring, options, "","", AbstractString[], ChunkOutput[]) end end diff --git a/src/display_methods.jl b/src/display_methods.jl index b8e7116..22fec59 100644 --- a/src/display_methods.jl +++ b/src/display_methods.jl @@ -60,7 +60,7 @@ end #Text is written to stdout, called from "term" mode chunks function Base.display(report::Report, m::MIME"text/plain", data) s = reprmime(m, data) - print("\n" * s) + println(s) end #Catch "rich_output" diff --git a/src/format.jl b/src/format.jl index 9f0bbd5..95ea62b 100644 --- a/src/format.jl +++ b/src/format.jl @@ -182,7 +182,7 @@ function format_chunk(chunk::CodeChunk, formatdict, docformat) if !chunk.options[:eval] if chunk.options[:echo] - result = "$(formatdict[:codestart])$(chunk.content)\n$(formatdict[:codeend])" + result = "$(formatdict[:codestart])\n$(chunk.content)$(formatdict[:codeend])" return result else r = "" @@ -196,7 +196,7 @@ function format_chunk(chunk::CodeChunk, formatdict, docformat) if chunk.options[:echo] #Convert to output format and highlight (html, tex...) if needed - result = "$(formatdict[:codestart])$(chunk.content)\n$(formatdict[:codeend])\n" + result = "$(formatdict[:codestart])$(chunk.content)$(formatdict[:codeend])\n" else result = "" end diff --git a/src/readers.jl b/src/readers.jl index 24b8b23..b13503d 100644 --- a/src/readers.jl +++ b/src/readers.jl @@ -129,8 +129,6 @@ function parse_doc(document::AbstractString, format::MarkupInput) end if ismatch(codeend, line) && state=="code" - - chunk = CodeChunk(content, codeno, start_line, optionString, options) codeno+=1 @@ -142,7 +140,7 @@ function parse_doc(document::AbstractString, format::MarkupInput) end if lineno == 1 - content *= line + content *= line else content *= "\n" * line end @@ -310,6 +308,6 @@ function parse_inline(text::AbstractString, inline_ex::Regex) codeno += 1 end push!(res, InlineText(text[e:end], e, length(text), textno)) - + return res -end \ No newline at end of file +end diff --git a/test/documents/chunk_options.noweb b/test/documents/chunk_options.noweb index 0dc98c7..e132208 100644 --- a/test/documents/chunk_options.noweb +++ b/test/documents/chunk_options.noweb @@ -3,6 +3,12 @@ y= [2, 5, 12] @ +<>= +x = 1:10 +d = Dict("Weave" => "testing") +y = [2, 4 ,8] +@ + <<>>= x = [12, 10] println(y) diff --git a/test/documents/chunk_options_ref.md b/test/documents/chunk_options_ref.md index 34a4e28..8f47039 100644 --- a/test/documents/chunk_options_ref.md +++ b/test/documents/chunk_options_ref.md @@ -4,6 +4,25 @@ julia> y= [2, 5, 12] 2 5 12 + +~~~~~~~~~~~~~ + + + +~~~~{.julia} +julia> x = 1:10 +1:10 + +julia> d = Dict("Weave" => "testing") +Dict{String,String} with 1 entry: + "Weave" => "testing" + +julia> y = [2, 4 ,8] +3-element Array{Int64,1}: + 2 + 4 + 8 + ~~~~~~~~~~~~~ @@ -15,7 +34,7 @@ println(y) ~~~~ -[2,5,12] +[2,4,8] ~~~~ @@ -44,6 +63,7 @@ Results without code ~~~~{.julia} + y = randn(5) println("Don't eval, but show code") ~~~~~~~~~~~~~ diff --git a/test/documents/tangle/chunk_options.jl.ref b/test/documents/tangle/chunk_options.jl.ref index efc2dff..e6c6d0d 100644 --- a/test/documents/tangle/chunk_options.jl.ref +++ b/test/documents/tangle/chunk_options.jl.ref @@ -1,23 +1,37 @@ y= [2, 5, 12] + +x = 1:10 +d = Dict("Weave" => "testing") +y = [2, 4 ,8] + + x = [12, 10] println(y) println(x) + println("Results without code") println(x) + y = 1:5 println(y) + a = "Don't print me" println(a) + println("No markup for results.") -println(collect(0:10:1000)) println(collect(0:10:1000)) + println(collect(0:10:1000)) + + +println(collect(0:10:1000)) + diff --git a/test/documents/test_hold_ref.md b/test/documents/test_hold_ref.md index b84077f..abb20fc 100644 --- a/test/documents/test_hold_ref.md +++ b/test/documents/test_hold_ref.md @@ -49,8 +49,8 @@ display(x) julia> using Gadfly julia> x = 1:10 - 1:10 + julia> plot(x = x, y = x) ~~~~~~~~~~~~~ @@ -73,6 +73,7 @@ julia> plot(x = x, y = x) ~~~~{.julia} julia> display(x) 1:10 + ~~~~~~~~~~~~~ @@ -85,8 +86,8 @@ julia> display(x) julietta> using Gadfly julietta> x = 1:10 - 1:10 + julietta> plot(x = x, y = x) ~~~~~~~~~~~~~ @@ -109,6 +110,7 @@ julietta> plot(x = x, y = x) ~~~~{.julia} julietta> display(x) 1:10 + ~~~~~~~~~~~~~ @@ -175,8 +177,8 @@ display(x) julia> using Gadfly julia> x = 1:10 - 1:10 + julia> plot(x = x, y = x) ~~~~~~~~~~~~~ @@ -199,6 +201,7 @@ julia> plot(x = x, y = x) ~~~~{.julia} julia> display(x) 1:10 + ~~~~~~~~~~~~~ @@ -219,8 +222,7 @@ display(x) ~~~~ -1:10 -1:10 +1:101:10 ~~~~