Added github markdown to formats, changed fig size defaults

pull/17/head
Matti Pastell 2014-12-05 10:37:02 +02:00
parent 7239424432
commit 63935ccf87
5 changed files with 44 additions and 24 deletions

View File

@ -9,6 +9,6 @@ plot(x=x, y = cos(x), Geom.line)
@
<<>>=
x = linspace(0, 200);
x = linspace(0, 200)
println(x)
@

View File

@ -75,10 +75,6 @@ function weave(source ; doctype = "pandoc", plotlib="PyPlot", informat="noweb",
elseif l_plotlib == "gadfly"
eval(parse("""include(Pkg.dir("JuliaReport","src","gadfly.jl"))"""))
rcParams[:plotlib] = "Gadfly"
if rcParams[:chunk_defaults][:fig_ext] != ".png"
rcParams[:chunk_defaults][:fig_ext] = ".png"
warn("Saving figures as .png with Gadfly")
end
end
end
@ -240,5 +236,3 @@ include("config.jl")
include("readers.jl")
include("formatters.jl")
end

View File

@ -8,8 +8,8 @@ const rcParams =
:include=> true,
:eval => true,
:fig_cap=> false,
:fig_width => 8, #Size in inches
:fig_height => 6,
:fig_width => 6, #Size in inches
:fig_height => 4,
:fig_path=> "figures",
:out_width=> nothing, #Defined separately for each format
:out_height=> nothing,

View File

@ -132,11 +132,11 @@ const texminted = Tex(@compat Dict{Symbol,Any}(:codestart => "\\begin{minted}[ma
:doctype => "texminted"
))
type Pandoc
type Markdown
formatdict::Dict{Symbol,Any}
end
const pandoc = Pandoc(@compat Dict{Symbol,Any}(:codestart => "~~~~{.julia}",
const pandoc = Markdown(@compat Dict{Symbol,Any}(:codestart => "~~~~{.julia}",
:codeend=>"~~~~~~~~~~~~~\n\n",
:outputstart=>"~~~~{.julia}",
:outputend=>"~~~~~~~~~~~~~\n\n",
@ -146,6 +146,17 @@ const pandoc = Pandoc(@compat Dict{Symbol,Any}(:codestart => "~~~~{.julia}",
))
const github = Markdown(@compat Dict{Symbol,Any}(:codestart => "````julia",
:codeend=> "````\n\n",
:outputstart=> "````julia",
:outputend=> "````\n\n",
:fig_ext=> ".png",
:extension=> "md",
:doctype=> "github"
))
function formatfigures(chunk, docformat::Tex)
fignames = chunk[:figure]
caption = chunk[:fig_cap]
@ -188,7 +199,7 @@ function formatfigures(chunk, docformat::Tex)
return result
end
function formatfigures(chunk, docformat::Pandoc)
function formatfigures(chunk, docformat::Markdown)
fignames = chunk[:figure]
caption = chunk[:fig_cap]
result = ""
@ -204,7 +215,7 @@ function formatfigures(chunk, docformat::Pandoc)
end
else
for fig in fignames
result *= "![]($fig)\\\n"
result *= "![]($fig)\n"
end
end
return result
@ -214,4 +225,6 @@ end
#Add new supported formats here
const formats = @compat Dict{String, Any}("tex" => tex,
"texminted" => texminted,
"pandoc" => pandoc)
"pandoc" => pandoc,
"github" => github
)

View File

@ -6,10 +6,10 @@ Gadfly.set_default_plot_format(:png)
function Base.display(report::Report, m::MIME"image/png", p::Plot)
chunk = report.cur_chunk
if chunk[:fig_ext] != ".png"
chunk[:fig_ext]
warn("Saving figures as .png with Gadfly")
end
#if chunk[:fig_ext] != ".png"
# chunk[:fig_ext]
# warn("Saving figures as .png with Gadfly")
#end
full_name, rel_name = get_figname(report, chunk)
@ -29,11 +29,24 @@ function Base.display(report::Report, m::MIME"image/png", p::Plot)
report.fignum += 1
#TODO other formats
#r = chunk[:dpi]/96 #Relative to Gadfly default 96dpi
#TODO Look for a corre
#Can't specify dpi in Gadfly? Opened Gadfly issue #504
w = chunk[:fig_width]inch
h = chunk[:fig_height]inch
format = chunk[:fig_ext]
@show format
draw(PNG(full_name, chunk[:fig_width]inch, chunk[:fig_height]inch), p)
#out = open(full_name, "w")
#writemime(out, m, data)
#close(out)
#This is probably not the correct way to handle different formats, but it works.
if format == ".png"
draw(PNG(full_name, w, h), p)
elseif format == ".pdf"
draw(PDF(full_name, w, h), p)
elseif format == ".ps"
draw(PS(full_name, w, h), p)
elseif format == ".svg"
draw(SVG(full_name, w, h), p)
elseif format == ".js.svg"
draw(SVGJS(full_name, w, h), p)
else:
warn("Can't save figure. Unsupported format")
end
end