generate pandoc-crossref style labels for figures

also clean up attrib code
pull/120/head
Dave Kleinschmidt 2018-02-01 13:13:11 -05:00
parent eead8f24a8
commit b4ebf0cd16
1 changed files with 11 additions and 8 deletions

View File

@ -369,7 +369,10 @@ end
function formatfigures(chunk, docformat::Pandoc) function formatfigures(chunk, docformat::Pandoc)
fignames = chunk.figures fignames = chunk.figures
length(fignames) > 0 || (return "")
caption = chunk.options[:fig_cap] caption = chunk.options[:fig_cap]
label = get(chunk.options, :label, nothing)
result = "" result = ""
figstring = "" figstring = ""
attribs = "" attribs = ""
@ -377,21 +380,21 @@ function formatfigures(chunk, docformat::Pandoc)
height = chunk.options[:out_height] height = chunk.options[:out_height]
#Build figure attibutes #Build figure attibutes
width == nothing || (attribs = "width=$width") attribs = String[]
(attribs "" && height nothing ) && (attribs *= " ") width == nothing || push!(attribs, "width=$width")
height == nothing || (attribs *= "height=$height") height == nothing || push!(attribs, "height=$height")
attribs == "" || (attribs = "{$attribs}") label == nothing || push!(attribs, "#fig:$label")
length(fignames) > 0 || (return "") attribs = join(attribs, " ")
if caption != nothing if caption != nothing
result *= "![$caption]($(fignames[1]))$attribs\n" result *= "![$caption]($(fignames[1])){$attribs}\n"
for fig = fignames[2:end] for fig = fignames[2:end]
result *= "![]($fig)$attribs\n" result *= "![]($fig){$attribs}\n"
println("Warning, only the first figure gets a caption\n") println("Warning, only the first figure gets a caption\n")
end end
else else
for fig in fignames for fig in fignames
result *= "![]($fig)$attribs\\ \n\n" result *= "![]($fig){$attribs}\\ \n\n"
end end
end end
return result return result