diff --git a/examples/gadfly_md_sample.jmd b/examples/gadfly_md_sample.jmd
index 7188c6f..ffbb238 100644
--- a/examples/gadfly_md_sample.jmd
+++ b/examples/gadfly_md_sample.jmd
@@ -1,8 +1,8 @@
-% Intro to Weave.jl with Gadfly
-% Matti Pastell
-% 20th April 2016
+# Intro to Weave.jl with Gadfly
-# Introduction
+Matti Pastell, 13th December 2016
+
+## Introduction
This a sample [Julia](http://julialang.org/) noweb document that can
be executed using [Weave.jl](https://github.com/mpastell/Weave.jl).
@@ -31,7 +31,7 @@ weave(Pkg.dir("Weave","examples","gadfly_md_sample.jmd"), informat="markdown",
*The documents will be written to the Julia working directory when you
use the `out_path = :pwd`.*
-# Capturing code
+## Capturing code
The basic code chunk will be run with default options and the code and
output will be captured.
@@ -60,11 +60,11 @@ syntax from the source document):
plot(y = cumsum(randn(1000, 1)), Geom.line)
```
-# Whats next
+## Whats next
Read the documentation:
- - stable:
- - latest:
+ - stable: [http://mpastell.github.io/Weave.jl/stable/](http://mpastell.github.io/Weave.jl/stable/)
+ - latest: [http://mpastell.github.io/Weave.jl/latest/](http://mpastell.github.io/Weave.jl/latest/)
-See other examples in:
+See other examples in the [Github repo](https://github.com/mpastell/Weave.jl/tree/master/examples)
diff --git a/src/format.jl b/src/format.jl
index bbd19ba..fd25800 100644
--- a/src/format.jl
+++ b/src/format.jl
@@ -13,6 +13,7 @@ function format(doc::WeaveDoc)
get!(formatdict, :fig_pos, nothing)
get!(formatdict, :fig_env, nothing)
+ docformat.formatdict[:cwd] = doc.cwd #pass wd to figure formatters
for chunk in copy(doc.chunks)
result = format_chunk(chunk, formatdict, docformat)
@@ -76,6 +77,8 @@ function format_chunk(chunk::CodeChunk, formatdict, docformat)
chunk.content = indent(chunk.content, formatdict[:indent])
end
+ chunk.content = format_code(chunk.content, docformat)
+
if !chunk.options[:eval]
if chunk.options[:echo]
result = "$(formatdict[:codestart])$(chunk.content)\n$(formatdict[:codeend])"
@@ -92,8 +95,7 @@ function format_chunk(chunk::CodeChunk, formatdict, docformat)
if chunk.options[:echo]
#Convert to output format and highlight (html, tex...) if needed
- formatted_code = format_code(chunk.content, docformat)
- result = "$(formatdict[:codestart])$(formatted_code)\n$(formatdict[:codeend])\n"
+ result = "$(formatdict[:codestart])$(chunk.content)\n$(formatdict[:codeend])\n"
else
result = ""
end
@@ -127,7 +129,6 @@ function format_chunk(chunk::CodeChunk, formatdict, docformat)
end
end
-
return result
end
diff --git a/src/formatters.jl b/src/formatters.jl
index f0efeca..93b4ce4 100644
--- a/src/formatters.jl
+++ b/src/formatters.jl
@@ -119,6 +119,19 @@ type MultiMarkdown
formatdict::Dict{Symbol,Any}
end
+function img_to_base64(fig, ext, cwd)
+ f = open(joinpath(cwd, fig), "r")
+ raw = read(f)
+ close(f)
+ if ext == ".png"
+ return "data:image/png;base64," * stringmime(MIME("image/png"), raw)
+ elseif ext == ".svg"
+ return "data:image/svg+xml;base64," * stringmime(MIME("image/svg+xml"), raw)
+ else
+ return(fig)
+ end
+end
+
function formatfigures(chunk, docformat::JMarkdown2HTML)
fignames = chunk.figures
caption = chunk.options[:fig_cap]
@@ -135,11 +148,16 @@ function formatfigures(chunk, docformat::JMarkdown2HTML)
(attribs != "" && height != nothing ) && (attribs *= ",")
height == nothing || (attribs *= " height=\"$height\" ")
- if f_env != nothing
+ if caption != nothing
result *= """\n"""
end
for fig = fignames
+ ext = splitext(fig)[2]
+ if ext == ".png" || ext == ".svg"
+ fig = img_to_base64(fig, ext, docformat.formatdict[:cwd])
+ end
+
figstring *= """\n"""
end
@@ -151,17 +169,13 @@ function formatfigures(chunk, docformat::JMarkdown2HTML)
"""
end
- if f_env != nothing
+ if caption != nothing
result *= "\n"
end
return result
end
-
-
-
-
const multimarkdown = MultiMarkdown("MultiMarkdown",
Dict{Symbol,Any}(
:codestart => "````julia",
@@ -320,7 +334,7 @@ end
function formatfigures(chunk, docformat::MultiMarkdown)
fignames = chunk.figures
caption = chunk.options[:fig_cap]
- result = ""J
+ result = ""
figstring = ""
if chunk.options[:out_width] == nothing