Change pandoc output to output inline images if there is no caption

pull/35/head
Matti Pastell 2016-04-19 16:47:53 +03:00
parent 526646bb79
commit 1ede33365b
5 changed files with 58 additions and 15 deletions

View File

@ -3,6 +3,7 @@
### In master
* Change pandoc output to use inline images if there is no caption
* Use Documenter.jl for documentation
* Add chunk option `hold`, replaces results = "hold". This way you can use e.g. `hold = true, results=raw`.

View File

@ -82,7 +82,7 @@ Weave an input document to output file.
* `plotlib`: `"PyPlot"`, `"Gadfly"` or `nothing`
* `informat`: `"noweb"` of `"markdown"`
* `out_path`: Path where the output is generated. Can be: `:doc`: Path of the source document, `:pwd`: Julia working directory,
`"somepath"`: Path as a AbstractString e.g `"/home/mpastell/weaveout"`
`"somepath"`: Path as a String e.g `"/home/mpastell/weaveout"`
* `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`.
* `cache_path`: where of cached output will be saved.

View File

@ -170,12 +170,14 @@ const texminted = Tex("Latex using minted for highlighting",
:doctype => "texminted"
))
type Markdown
description::AbstractString
formatdict::Dict{Symbol,Any}
type Pandoc
description::AbstractString
formatdict::Dict{Symbol,Any}
end
const pandoc = Markdown("Pandoc markdown",
const pandoc = Pandoc("Pandoc markdown",
@compat Dict{Symbol,Any}(
:codestart => "~~~~{.julia}",
:codeend=>"~~~~~~~~~~~~~\n\n",
@ -186,6 +188,11 @@ const pandoc = Markdown("Pandoc markdown",
:doctype=>"pandoc"
))
type Markdown
description::AbstractString
formatdict::Dict{Symbol,Any}
end
const github = Markdown("Github markdown",
@compat Dict{Symbol,Any}(
@ -304,6 +311,31 @@ function formatfigures(chunk, docformat::Markdown)
return result
end
function formatfigures(chunk, docformat::Pandoc)
fignames = chunk.figures
caption = chunk.options[:fig_cap]
result = ""
figstring = ""
length(fignames) > 0 || (return "")
if caption != nothing
result *= "![$caption]($(fignames[1]))\n"
for fig = fignames[2:end]
result *= "![]($fig)\n"
println("Warning, only the first figure gets a caption\n")
end
else
for fig in fignames
result *= "![]($fig)\\ \n\n"
end
end
return result
end
function formatfigures(chunk, docformat::Rest)
fignames = chunk.figures

View File

@ -16,7 +16,8 @@ plot(x=x, y = sin(x), Geom.line)
![](figures/gadfly_formats_test_cos2_fun_1.png)
![](figures/gadfly_formats_test_cos2_fun_1.png)\
@ -29,7 +30,8 @@ julia> plot(x=x, y = sin(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_1.png)
![](figures/gadfly_formats_test_4_1.png)\
~~~~{.julia}
julia> y = 20
@ -39,7 +41,8 @@ julia> plot(x=x, y = cos(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_2.png)
![](figures/gadfly_formats_test_4_2.png)\
@ -50,7 +53,8 @@ plot(x=x, y = sin(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_5_1.png)
![](figures/gadfly_formats_test_5_1.png)\
~~~~{.julia}
y = 20
@ -58,4 +62,5 @@ plot(x=x, y = cos(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_5_2.png)
![](figures/gadfly_formats_test_5_2.png)\

View File

@ -16,7 +16,8 @@ plot(x=x, y = sin(x), Geom.line)
![](figures/gadfly_formats_test_cos2_fun_1.svg)
![](figures/gadfly_formats_test_cos2_fun_1.svg)\
@ -29,7 +30,8 @@ julia> plot(x=x, y = sin(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_1.svg)
![](figures/gadfly_formats_test_4_1.svg)\
~~~~{.julia}
julia> y = 20
@ -39,7 +41,8 @@ julia> plot(x=x, y = cos(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_4_2.svg)
![](figures/gadfly_formats_test_4_2.svg)\
@ -50,7 +53,8 @@ plot(x=x, y = sin(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_5_1.svg)
![](figures/gadfly_formats_test_5_1.svg)\
~~~~{.julia}
y = 20
@ -58,4 +62,5 @@ plot(x=x, y = cos(x), Geom.line)
~~~~~~~~~~~~~
![](figures/gadfly_formats_test_5_2.svg)
![](figures/gadfly_formats_test_5_2.svg)\