mirror of https://github.com/mpastell/Weave.jl
Make string AbstractStrings
parent
178c295605
commit
0e44f9683c
20
src/Weave.jl
20
src/Weave.jl
|
@ -6,19 +6,19 @@ using Docile
|
||||||
|
|
||||||
#Contains report global properties
|
#Contains report global properties
|
||||||
type Report <: Display
|
type Report <: Display
|
||||||
cwd::String
|
cwd::AbstractString
|
||||||
basename::String
|
basename::AbstractString
|
||||||
formatdict::Dict{Symbol,Any}
|
formatdict::Dict{Symbol,Any}
|
||||||
pending_code::String
|
pending_code::AbstractString
|
||||||
cur_result::String
|
cur_result::AbstractString
|
||||||
fignum::Int
|
fignum::Int
|
||||||
figures::Array{String}
|
figures::Array{AbstractString}
|
||||||
term_state::Symbol
|
term_state::Symbol
|
||||||
cur_chunk
|
cur_chunk
|
||||||
end
|
end
|
||||||
|
|
||||||
function Report(cwd, basename, formatdict)
|
function Report(cwd, basename, formatdict)
|
||||||
Report(cwd, basename, formatdict, "", "", 1, String[], :text, nothing)
|
Report(cwd, basename, formatdict, "", "", 1, AbstractString[], :text, nothing)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
@ -40,7 +40,7 @@ end
|
||||||
@doc "List supported output formats" ->
|
@doc "List supported output formats" ->
|
||||||
function list_out_formats()
|
function list_out_formats()
|
||||||
for format = keys(formats)
|
for format = keys(formats)
|
||||||
println(string(format,": ", formats[format].description))
|
println(AbstractString(format,": ", formats[format].description))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -55,7 +55,7 @@ tangle(source ; out_path=:doc, informat="noweb")
|
||||||
|
|
||||||
* `informat`: `"noweb"` of `"markdown"`
|
* `informat`: `"noweb"` of `"markdown"`
|
||||||
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory,
|
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory,
|
||||||
`"somepath"`: Path as a string e.g `"/home/mpastell/weaveout"`
|
`"somepath"`: Path as a AbstractString e.g `"/home/mpastell/weaveout"`
|
||||||
"""->
|
"""->
|
||||||
function tangle(source ; out_path=:doc, informat="noweb")
|
function tangle(source ; out_path=:doc, informat="noweb")
|
||||||
doc = read_doc(source, informat)
|
doc = read_doc(source, informat)
|
||||||
|
@ -87,7 +87,7 @@ weave(source ; doctype = "pandoc", plotlib="Gadfly",
|
||||||
* `plotlib`: `"PyPlot"`, `"Gadfly"`, or `"Winston"`
|
* `plotlib`: `"PyPlot"`, `"Gadfly"`, or `"Winston"`
|
||||||
* `informat`: `"noweb"` of `"markdown"`
|
* `informat`: `"noweb"` of `"markdown"`
|
||||||
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory,
|
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory,
|
||||||
`"somepath"`: Path as a string e.g `"/home/mpastell/weaveout"`
|
`"somepath"`: Path as a AbstractString e.g `"/home/mpastell/weaveout"`
|
||||||
* `fig_path`: where figures will be generated, relative to out_path
|
* `fig_path`: where figures will be generated, relative to out_path
|
||||||
* `fig_ext`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`.
|
* `fig_ext`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`.
|
||||||
* `cache_path`: where of cached output will be saved.
|
* `cache_path`: where of cached output will be saved.
|
||||||
|
@ -121,7 +121,7 @@ function Base.display(report::Report, m::MIME"text/plain", data)
|
||||||
#report.cur_result *= "\n" * s
|
#report.cur_result *= "\n" * s
|
||||||
end
|
end
|
||||||
|
|
||||||
function weave(doc::String, doctype::String)
|
function weave(doc::AbstractString, doctype::AbstractString)
|
||||||
weave(doc, doctype=doctype)
|
weave(doc, doctype=doctype)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -1,12 +1,12 @@
|
||||||
|
|
||||||
type WeaveDoc
|
type WeaveDoc
|
||||||
source::String
|
source::AbstractString
|
||||||
basename::String
|
basename::AbstractString
|
||||||
path::String
|
path::AbstractString
|
||||||
chunks::Array
|
chunks::Array
|
||||||
cwd::String
|
cwd::AbstractString
|
||||||
format
|
format
|
||||||
doctype::String
|
doctype::AbstractString
|
||||||
function WeaveDoc(source, chunks)
|
function WeaveDoc(source, chunks)
|
||||||
path, fname = splitdir(abspath(source))
|
path, fname = splitdir(abspath(source))
|
||||||
basename = splitext(fname)[1]
|
basename = splitext(fname)[1]
|
||||||
|
@ -15,29 +15,29 @@ type WeaveDoc
|
||||||
end
|
end
|
||||||
|
|
||||||
immutable ChunkOutput
|
immutable ChunkOutput
|
||||||
code::String
|
code::AbstractString
|
||||||
stdout::String
|
stdout::AbstractString
|
||||||
displayed::String
|
displayed::AbstractString
|
||||||
figures::Array{String}
|
figures::Array{AbstractString}
|
||||||
end
|
end
|
||||||
|
|
||||||
type CodeChunk
|
type CodeChunk
|
||||||
content::String
|
content::AbstractString
|
||||||
number::Int
|
number::Int
|
||||||
result_no::Int
|
result_no::Int
|
||||||
start_line::Int
|
start_line::Int
|
||||||
option_string::String
|
option_AbstractString::AbstractString
|
||||||
options::Dict{Symbol, Any}
|
options::Dict{Symbol, Any}
|
||||||
output::String
|
output::AbstractString
|
||||||
figures::Array{String}
|
figures::Array{AbstractString}
|
||||||
result::Array{ChunkOutput}
|
result::Array{ChunkOutput}
|
||||||
function CodeChunk(content, number, start_line, option_string, options)
|
function CodeChunk(content, number, start_line, option_AbstractString, options)
|
||||||
new(content, number, 0, start_line, option_string, options, "", String[], ChunkOutput[])
|
new(content, number, 0, start_line, option_AbstractString, options, "", AbstractString[], ChunkOutput[])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
type DocChunk
|
type DocChunk
|
||||||
content::String
|
content::AbstractString
|
||||||
number::Int
|
number::Int
|
||||||
start_line::Int
|
start_line::Int
|
||||||
end
|
end
|
||||||
|
|
|
@ -22,7 +22,7 @@ const rcParams =
|
||||||
:wrap=> true,
|
:wrap=> true,
|
||||||
:line_width => 75,
|
:line_width => 75,
|
||||||
:engine=> "julia",
|
:engine=> "julia",
|
||||||
#:option_string=> "",
|
#:option_AbstractString=> "",
|
||||||
#Defined in formats
|
#Defined in formats
|
||||||
:fig_ext => nothing,
|
:fig_ext => nothing,
|
||||||
:fig_pos=> nothing,
|
:fig_pos=> nothing,
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
function format(doc::WeaveDoc)
|
function format(doc::WeaveDoc)
|
||||||
formatted = String[]
|
formatted = AbstractString[]
|
||||||
docformat = doc.format
|
docformat = doc.format
|
||||||
#@show docformat
|
#@show docformat
|
||||||
|
|
||||||
|
@ -105,12 +105,12 @@ end
|
||||||
|
|
||||||
function indent(text, nindent)
|
function indent(text, nindent)
|
||||||
return join(map(x->
|
return join(map(x->
|
||||||
string(repeat(" ", nindent), x), split(text, "\n")), "\n")
|
AbstractString(repeat(" ", nindent), x), split(text, "\n")), "\n")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function wraplines(text, line_width=75)
|
function wraplines(text, line_width=75)
|
||||||
result = String[]
|
result = AbstractString[]
|
||||||
lines = split(text, "\n")
|
lines = split(text, "\n")
|
||||||
for line in lines
|
for line in lines
|
||||||
if length(line) > line_width
|
if length(line) > line_width
|
||||||
|
@ -135,7 +135,7 @@ end
|
||||||
|
|
||||||
|
|
||||||
type Tex
|
type Tex
|
||||||
description::String
|
description::AbstractString
|
||||||
formatdict::Dict{Symbol,Any}
|
formatdict::Dict{Symbol,Any}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -171,7 +171,7 @@ const texminted = Tex("Latex using minted for highlighting",
|
||||||
))
|
))
|
||||||
|
|
||||||
type Markdown
|
type Markdown
|
||||||
description::String
|
description::AbstractString
|
||||||
formatdict::Dict{Symbol,Any}
|
formatdict::Dict{Symbol,Any}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ const github = Markdown("Github markdown",
|
||||||
|
|
||||||
|
|
||||||
type Rest
|
type Rest
|
||||||
description::String
|
description::AbstractString
|
||||||
formatdict::Dict{Symbol,Any}
|
formatdict::Dict{Symbol,Any}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -218,7 +218,7 @@ const rst = Rest("reStructuredText and Sphinx",
|
||||||
))
|
))
|
||||||
|
|
||||||
type AsciiDoc
|
type AsciiDoc
|
||||||
description::String
|
description::AbstractString
|
||||||
formatdict::Dict{Symbol,Any}
|
formatdict::Dict{Symbol,Any}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -243,7 +243,7 @@ function formatfigures(chunk, docformat::Tex)
|
||||||
f_pos = chunk.options[:fig_pos]
|
f_pos = chunk.options[:fig_pos]
|
||||||
f_env = chunk.options[:fig_env]
|
f_env = chunk.options[:fig_env]
|
||||||
result = ""
|
result = ""
|
||||||
figstring = ""
|
figAbstractString = ""
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -254,19 +254,19 @@ function formatfigures(chunk, docformat::Tex)
|
||||||
|
|
||||||
for fig = fignames
|
for fig = fignames
|
||||||
if splitext(fig)[2] == ".tex" #Tikz figures
|
if splitext(fig)[2] == ".tex" #Tikz figures
|
||||||
figstring *= "\\resizebox{$width}{!}{\\input{$fig}}\n"
|
figAbstractString *= "\\resizebox{$width}{!}{\\input{$fig}}\n"
|
||||||
else
|
else
|
||||||
figstring *= "\\includegraphics[width=$width]{$fig}\n"
|
figAbstractString *= "\\includegraphics[width=$width]{$fig}\n"
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
# Figure environment
|
# Figure environment
|
||||||
if caption != nothing
|
if caption != nothing
|
||||||
result *= string("\\center\n",
|
result *= AbstractString("\\center\n",
|
||||||
"$figstring",
|
"$figAbstractString",
|
||||||
"\\caption{$caption}\n")
|
"\\caption{$caption}\n")
|
||||||
else
|
else
|
||||||
result *= figstring
|
result *= figAbstractString
|
||||||
end
|
end
|
||||||
|
|
||||||
if chunk.options[:name] != nothing && f_env !=nothing
|
if chunk.options[:name] != nothing && f_env !=nothing
|
||||||
|
@ -286,7 +286,7 @@ function formatfigures(chunk, docformat::Markdown)
|
||||||
fignames = chunk.figures
|
fignames = chunk.figures
|
||||||
caption = chunk.options[:fig_cap]
|
caption = chunk.options[:fig_cap]
|
||||||
result = ""
|
result = ""
|
||||||
figstring = ""
|
figAbstractString = ""
|
||||||
|
|
||||||
length(fignames) > 0 || (return "")
|
length(fignames) > 0 || (return "")
|
||||||
|
|
||||||
|
@ -310,18 +310,18 @@ function formatfigures(chunk, docformat::Rest)
|
||||||
caption = chunk.options[:fig_cap]
|
caption = chunk.options[:fig_cap]
|
||||||
width = chunk.options[:out_width]
|
width = chunk.options[:out_width]
|
||||||
result = ""
|
result = ""
|
||||||
figstring = ""
|
figAbstractString = ""
|
||||||
|
|
||||||
for fig=fignames
|
for fig=fignames
|
||||||
figstring *= @sprintf(".. image:: %s\n :width: %s\n\n", fig, width)
|
figAbstractString *= @sprintf(".. image:: %s\n :width: %s\n\n", fig, width)
|
||||||
end
|
end
|
||||||
|
|
||||||
if caption != nothing
|
if caption != nothing
|
||||||
result *= string(".. figure:: $(fignames[1])\n",
|
result *= AbstractString(".. figure:: $(fignames[1])\n",
|
||||||
" :width: $width\n\n",
|
" :width: $width\n\n",
|
||||||
" $caption\n\n")
|
" $caption\n\n")
|
||||||
else
|
else
|
||||||
result *= figstring
|
result *= figAbstractString
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -332,27 +332,27 @@ function formatfigures(chunk, docformat::AsciiDoc)
|
||||||
caption = chunk.options[:fig_cap]
|
caption = chunk.options[:fig_cap]
|
||||||
width = chunk.options[:out_width]
|
width = chunk.options[:out_width]
|
||||||
result = ""
|
result = ""
|
||||||
figstring = ""
|
figAbstractString = ""
|
||||||
|
|
||||||
|
|
||||||
for fig=fignames
|
for fig=fignames
|
||||||
figstring *= @sprintf("image::%s[width=%s]\n", fig, width)
|
figAbstractString *= @sprintf("image::%s[width=%s]\n", fig, width)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
if caption != nothing
|
if caption != nothing
|
||||||
result *= string("image::$(fignames[1])",
|
result *= AbstractString("image::$(fignames[1])",
|
||||||
"[width=$width,",
|
"[width=$width,",
|
||||||
"title=\"$caption\"]")
|
"title=\"$caption\"]")
|
||||||
else
|
else
|
||||||
result *= figstring
|
result *= figAbstractString
|
||||||
return result
|
return result
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
#Add new supported formats here
|
#Add new supported formats here
|
||||||
const formats = @compat Dict{String, Any}("tex" => tex,
|
const formats = @compat Dict{AbstractString, Any}("tex" => tex,
|
||||||
"texminted" => texminted,
|
"texminted" => texminted,
|
||||||
"pandoc" => pandoc,
|
"pandoc" => pandoc,
|
||||||
"github" => github,
|
"github" => github,
|
||||||
|
|
|
@ -20,7 +20,7 @@ function Base.display(report::Report, m::MIME"image/png", p::Plot)
|
||||||
|
|
||||||
#report.cur_result *= formatfigures(chunk, docformat)
|
#report.cur_result *= formatfigures(chunk, docformat)
|
||||||
#report.term_state = :fig
|
#report.term_state = :fig
|
||||||
# chunk.figures = String[]
|
# chunk.figures = AbstractString[]
|
||||||
#else
|
#else
|
||||||
push!(report.figures, rel_name)
|
push!(report.figures, rel_name)
|
||||||
#end
|
#end
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
using PyPlot
|
using PyPlot
|
||||||
|
|
||||||
function savefigs_pyplot(chunk, report::Report)
|
function savefigs_pyplot(chunk, report::Report)
|
||||||
fignames = String[]
|
fignames = AbstractString[]
|
||||||
ext = report.formatdict[:fig_ext]
|
ext = report.formatdict[:fig_ext]
|
||||||
figpath = joinpath(report.cwd, chunk.options[:fig_path])
|
figpath = joinpath(report.cwd, chunk.options[:fig_path])
|
||||||
isdir(figpath) || mkdir(figpath)
|
isdir(figpath) || mkdir(figpath)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
pushopt(options::Dict,expr::Expr) = Base.Meta.isexpr(expr,:(=)) && (options[expr.args[1]] = expr.args[2])
|
pushopt(options::Dict,expr::Expr) = Base.Meta.isexpr(expr,:(=)) && (options[expr.args[1]] = expr.args[2])
|
||||||
|
|
||||||
|
|
||||||
const input_formats = @compat Dict{String, Any}(
|
const input_formats = @compat Dict{AbstractString, Any}(
|
||||||
"noweb" => Dict{Symbol, Any}(
|
"noweb" => Dict{Symbol, Any}(
|
||||||
:codestart => r"^<<(.*?)>>=\s*$",
|
:codestart => r"^<<(.*?)>>=\s*$",
|
||||||
:codeend => r"^@\s*$"
|
:codeend => r"^@\s*$"
|
||||||
|
@ -14,7 +14,7 @@ const input_formats = @compat Dict{String, Any}(
|
||||||
|
|
||||||
|
|
||||||
@doc "Read and parse input document" ->
|
@doc "Read and parse input document" ->
|
||||||
function read_doc(source::String, format="noweb"::String)
|
function read_doc(source::AbstractString, format="noweb"::AbstractString)
|
||||||
document = bytestring(open(source) do io
|
document = bytestring(open(source) do io
|
||||||
mmap_array(Uint8,(filesize(source),),io)
|
mmap_array(Uint8,(filesize(source),),io)
|
||||||
end)
|
end)
|
||||||
|
@ -22,8 +22,8 @@ function read_doc(source::String, format="noweb"::String)
|
||||||
doc = WeaveDoc(source, parsed)
|
doc = WeaveDoc(source, parsed)
|
||||||
end
|
end
|
||||||
|
|
||||||
@doc "Parse chunks from string" ->
|
@doc "Parse chunks from AbstractString" ->
|
||||||
function parse_doc(document::String, format="noweb"::String)
|
function parse_doc(document::AbstractString, format="noweb"::AbstractString)
|
||||||
#doctext = readall(open(document))
|
#doctext = readall(open(document))
|
||||||
lines = split(document, "\n")
|
lines = split(document, "\n")
|
||||||
|
|
||||||
|
@ -37,21 +37,21 @@ function parse_doc(document::String, format="noweb"::String)
|
||||||
start_line = 0
|
start_line = 0
|
||||||
|
|
||||||
options = Dict()
|
options = Dict()
|
||||||
optionstring = ""
|
optionAbstractString = ""
|
||||||
parsed = Any[]
|
parsed = Any[]
|
||||||
for lineno in 1:length(lines)
|
for lineno in 1:length(lines)
|
||||||
line = lines[lineno]
|
line = lines[lineno]
|
||||||
if (m = match(codestart, line)) != nothing && state=="doc"
|
if (m = match(codestart, line)) != nothing && state=="doc"
|
||||||
state = "code"
|
state = "code"
|
||||||
if m.captures[1] == nothing
|
if m.captures[1] == nothing
|
||||||
optionstring = ""
|
optionAbstractString = ""
|
||||||
else
|
else
|
||||||
optionstring=strip(m.captures[1])
|
optionAbstractString=strip(m.captures[1])
|
||||||
end
|
end
|
||||||
#@show optionstring
|
#@show optionAbstractString
|
||||||
options = Dict{Symbol,Any}()
|
options = Dict{Symbol,Any}()
|
||||||
if length(optionstring) > 0
|
if length(optionAbstractString) > 0
|
||||||
expr = parse(optionstring)
|
expr = parse(optionAbstractString)
|
||||||
Base.Meta.isexpr(expr,:(=)) && (options[expr.args[1]] = expr.args[2])
|
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)
|
Base.Meta.isexpr(expr,:toplevel) && map(pushopt,fill(options,length(expr.args)),expr.args)
|
||||||
end
|
end
|
||||||
|
@ -70,10 +70,10 @@ function parse_doc(document::String, format="noweb"::String)
|
||||||
end
|
end
|
||||||
if ismatch(codeend, line) && state=="code"
|
if ismatch(codeend, line) && state=="code"
|
||||||
|
|
||||||
chunk = CodeChunk(content, codeno, start_line, optionstring, options)
|
chunk = CodeChunk(content, codeno, start_line, optionAbstractString, options)
|
||||||
#chunk = @compat Dict{Symbol,Any}(:type => "code", :content => content,
|
#chunk = @compat Dict{Symbol,Any}(:type => "code", :content => content,
|
||||||
# :number => codeno, :options => options,
|
# :number => codeno, :options => options,
|
||||||
# :optionstring => optionstring,
|
# :optionAbstractString => optionAbstractString,
|
||||||
# :start_line => start_line)
|
# :start_line => start_line)
|
||||||
|
|
||||||
codeno+=1
|
codeno+=1
|
||||||
|
|
26
src/run.jl
26
src/run.jl
|
@ -11,7 +11,7 @@ function run(doc::WeaveDoc; doctype = "pandoc", plotlib="Gadfly", informat="nowe
|
||||||
* `plotlib`: `"PyPlot"`, `"Gadfly"`, or `"Winston"`
|
* `plotlib`: `"PyPlot"`, `"Gadfly"`, or `"Winston"`
|
||||||
* `informat`: `"noweb"` of `"markdown"`
|
* `informat`: `"noweb"` of `"markdown"`
|
||||||
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory,
|
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory,
|
||||||
`"somepath"`: Path as a string e.g `"/home/mpastell/weaveout"`
|
`"somepath"`: Path as a AbstractString e.g `"/home/mpastell/weaveout"`
|
||||||
* `fig_path`: where figures will be generated, relative to out_path
|
* `fig_path`: where figures will be generated, relative to out_path
|
||||||
* `fig_ext`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`.
|
* `fig_ext`: Extension for saved figures e.g. `".pdf"`, `".png"`. Default setting depends on `doctype`.
|
||||||
* `cache_path`: where of cached output will be saved.
|
* `cache_path`: where of cached output will be saved.
|
||||||
|
@ -89,7 +89,7 @@ end
|
||||||
|
|
||||||
function reset_report(report::Report)
|
function reset_report(report::Report)
|
||||||
report.cur_result = ""
|
report.cur_result = ""
|
||||||
report.figures = String[]
|
report.figures = AbstractString[]
|
||||||
report.term_state = :text
|
report.term_state = :text
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -131,7 +131,7 @@ function run_block(chunk::CodeChunk, report::Report, SandBox::Module)
|
||||||
else
|
else
|
||||||
@show input
|
@show input
|
||||||
content = "\n" * input * str_expr
|
content = "\n" * input * str_expr
|
||||||
rchunk = CodeChunk(content, chunk.number, chunk.start_line, chunk.option_string, copy(chunk.options))
|
rchunk = CodeChunk(content, chunk.number, chunk.start_line, chunk.option_AbstractString, copy(chunk.options))
|
||||||
input = ""
|
input = ""
|
||||||
rchunk.result_no = result_no
|
rchunk.result_no = result_no
|
||||||
result_no *=1
|
result_no *=1
|
||||||
|
@ -162,7 +162,7 @@ function run_term(chunk::CodeChunk, report::Report, SandBox::Module)
|
||||||
output *= prompt * str_expr
|
output *= prompt * str_expr
|
||||||
else
|
else
|
||||||
content = prompt * output * str_expr
|
content = prompt * output * str_expr
|
||||||
rchunk = CodeChunk(content, chunk.number, chunk.start_line, chunk.option_string, copy(chunk.options))
|
rchunk = CodeChunk(content, chunk.number, chunk.start_line, chunk.option_AbstractString, copy(chunk.options))
|
||||||
rchunk.output = content * out * displayed
|
rchunk.output = content * out * displayed
|
||||||
@show rchunk.output
|
@show rchunk.output
|
||||||
output = ""
|
output = ""
|
||||||
|
@ -193,14 +193,14 @@ function run_term2(code_str, report::Report, SandBox::Module)
|
||||||
code, pos = parse(code_str, pos)
|
code, pos = parse(code_str, pos)
|
||||||
|
|
||||||
report.term_state == :fig && (report.cur_result*= codestart)
|
report.term_state == :fig && (report.cur_result*= codestart)
|
||||||
prompts = string(prompt, rstrip(code_str[oldpos:(pos-1)]), "\n")
|
prompts = AbstractString(prompt, rstrip(code_str[oldpos:(pos-1)]), "\n")
|
||||||
report.cur_result *= prompts
|
report.cur_result *= prompts
|
||||||
report.term_state = :text
|
report.term_state = :text
|
||||||
s = eval(SandBox, code)
|
s = eval(SandBox, code)
|
||||||
s != nothing && display(s)
|
s != nothing && display(s)
|
||||||
end
|
end
|
||||||
|
|
||||||
return string(report.cur_result)
|
return AbstractString(report.cur_result)
|
||||||
end
|
end
|
||||||
|
|
||||||
function capture_output(expr::Expr, SandBox::Module, term, plotlib)
|
function capture_output(expr::Expr, SandBox::Module, term, plotlib)
|
||||||
|
@ -226,8 +226,8 @@ end
|
||||||
|
|
||||||
|
|
||||||
#Parse chunk input to array of expressions
|
#Parse chunk input to array of expressions
|
||||||
function parse_input(input::String)
|
function parse_input(input::AbstractString)
|
||||||
parsed = (String, Expr)[]
|
parsed = (AbstractString, Expr)[]
|
||||||
n = length(input)
|
n = length(input)
|
||||||
pos = 2 #The first character is extra line end
|
pos = 2 #The first character is extra line end
|
||||||
while pos < n
|
while pos < n
|
||||||
|
@ -281,7 +281,7 @@ end
|
||||||
function clear_sandbox(SandBox::Module)
|
function clear_sandbox(SandBox::Module)
|
||||||
for name = names(SandBox, true)
|
for name = names(SandBox, true)
|
||||||
if name != :eval && name != names(SandBox)[1]
|
if name != :eval && name != names(SandBox)[1]
|
||||||
try eval(SandBox, parse(string(string(name), "=nothing"))) end
|
try eval(SandBox, parse(AbstractString(AbstractString(name), "=nothing"))) end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -354,7 +354,7 @@ function collect_results(chunk::CodeChunk, fmt::ScriptResult)
|
||||||
content *= r.code
|
content *= r.code
|
||||||
else
|
else
|
||||||
content = "\n" * content * r.code
|
content = "\n" * content * r.code
|
||||||
rchunk = CodeChunk(content, chunk.number, chunk.start_line, chunk.option_string, copy(chunk.options))
|
rchunk = CodeChunk(content, chunk.number, chunk.start_line, chunk.option_AbstractString, copy(chunk.options))
|
||||||
content = ""
|
content = ""
|
||||||
rchunk.result_no = result_no
|
rchunk.result_no = result_no
|
||||||
result_no *=1
|
result_no *=1
|
||||||
|
@ -364,7 +364,7 @@ function collect_results(chunk::CodeChunk, fmt::ScriptResult)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if content != ""
|
if content != ""
|
||||||
rchunk = CodeChunk(content, chunk.number, chunk.start_line, chunk.option_string, copy(chunk.options))
|
rchunk = CodeChunk(content, chunk.number, chunk.start_line, chunk.option_AbstractString, copy(chunk.options))
|
||||||
push!(result_chunks, rchunk)
|
push!(result_chunks, rchunk)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -380,7 +380,7 @@ function collect_results(chunk::CodeChunk, fmt::TermResult)
|
||||||
output *= prompt * r.code
|
output *= prompt * r.code
|
||||||
output *= r.displayed * r.stdout
|
output *= r.displayed * r.stdout
|
||||||
if !isempty(r.figures)
|
if !isempty(r.figures)
|
||||||
rchunk = CodeChunk("", chunk.number, chunk.start_line, chunk.option_string, copy(chunk.options))
|
rchunk = CodeChunk("", chunk.number, chunk.start_line, chunk.option_AbstractString, copy(chunk.options))
|
||||||
rchunk.output = output
|
rchunk.output = output
|
||||||
output = ""
|
output = ""
|
||||||
rchunk.figures = r.figures
|
rchunk.figures = r.figures
|
||||||
|
@ -388,7 +388,7 @@ function collect_results(chunk::CodeChunk, fmt::TermResult)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if output != ""
|
if output != ""
|
||||||
rchunk = CodeChunk("", chunk.number, chunk.start_line, chunk.option_string, copy(chunk.options))
|
rchunk = CodeChunk("", chunk.number, chunk.start_line, chunk.option_AbstractString, copy(chunk.options))
|
||||||
rchunk.output = output
|
rchunk.output = output
|
||||||
push!(result_chunks, rchunk)
|
push!(result_chunks, rchunk)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in New Issue