mirror of https://github.com/mpastell/Weave.jl
use isnothing & isempty
parent
0760591021
commit
aa7fd311d8
|
@ -81,11 +81,11 @@ function formatfigures(chunk, docformat::JMarkdown2HTML)
|
|||
|
||||
# Set size
|
||||
attribs = ""
|
||||
width == nothing || (attribs = "width=\"$width\"")
|
||||
(attribs != "" && height != nothing) && (attribs *= ",")
|
||||
height == nothing || (attribs *= " height=\"$height\" ")
|
||||
isnothing(width) || (attribs = "width=\"$width\"")
|
||||
(!isempty(attribs) && !isnothing(height)) && (attribs *= ",")
|
||||
isnothing(height) || (attribs *= " height=\"$height\" ")
|
||||
|
||||
if caption != nothing
|
||||
if !isnothing(caption)
|
||||
result *= """<figure>\n"""
|
||||
end
|
||||
|
||||
|
@ -95,13 +95,13 @@ function formatfigures(chunk, docformat::JMarkdown2HTML)
|
|||
|
||||
result *= figstring
|
||||
|
||||
if caption != nothing
|
||||
if !isnothing(caption)
|
||||
result *= """
|
||||
<figcaption>$caption</figcaption>
|
||||
"""
|
||||
end
|
||||
|
||||
if caption != nothing
|
||||
if !isnothing(caption)
|
||||
result *= "</figure>\n"
|
||||
end
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ function formatfigures(chunk, docformat::GitHubMarkdown)
|
|||
|
||||
length(fignames) > 0 || (return "")
|
||||
|
||||
if caption != nothing
|
||||
if !isnothing(caption)
|
||||
result *= "![$caption]($(fignames[1]))\n"
|
||||
for fig in fignames[2:end]
|
||||
result *= "![]($fig)\n"
|
||||
|
@ -78,7 +78,7 @@ function formatfigures(chunk, docformat::Hugo)
|
|||
title_spec = ""
|
||||
else
|
||||
caption = chunk.options[:fig_cap]
|
||||
title_spec = caption == nothing ? "" : "title=\"$(caption)\" "
|
||||
title_spec = isnothing(caption) ? "" : "title=\"$(caption)\" "
|
||||
end
|
||||
"{{< figure src=\"$(joinpath(relpath, fig))\" $(title_spec) >}}"
|
||||
end
|
||||
|
@ -121,7 +121,7 @@ function formatfigures(chunk, docformat::MultiMarkdown)
|
|||
|
||||
length(fignames) > 0 || (return "")
|
||||
|
||||
if caption != nothing
|
||||
if !isnothing(caption)
|
||||
result *= "![$caption][$(fignames[1])]\n\n"
|
||||
result *= "[$(fignames[1])]: $(fignames[1]) $width\n"
|
||||
for fig in fignames[2:end]
|
||||
|
@ -176,12 +176,12 @@ function formatfigures(chunk, docformat::Pandoc)
|
|||
|
||||
# Build figure attibutes
|
||||
attribs = String[]
|
||||
width == nothing || push!(attribs, "width=$width")
|
||||
height == nothing || push!(attribs, "height=$height")
|
||||
label == nothing || push!(attribs, "#fig:$label")
|
||||
isnothing(width) || push!(attribs, "width=$width")
|
||||
isnothing(height) || push!(attribs, "height=$height")
|
||||
isnothing(label) || push!(attribs, "#fig:$label")
|
||||
attribs = isempty(attribs) ? "" : "{" * join(attribs, " ") * "}"
|
||||
|
||||
if caption != nothing
|
||||
if !isnothing(caption)
|
||||
result *= "![$caption]($(fignames[1]))$attribs\n"
|
||||
for fig in fignames[2:end]
|
||||
result *= "![]($fig)$attribs\n"
|
||||
|
|
|
@ -15,20 +15,20 @@ function formatfigures(chunk, docformat::TexFormat)
|
|||
result = ""
|
||||
figstring = ""
|
||||
|
||||
if f_env == nothing && caption != nothing
|
||||
if isnothing(f_env) && !isnothing(caption)
|
||||
f_env = "figure"
|
||||
end
|
||||
|
||||
(f_pos == nothing) && (f_pos = "!h")
|
||||
(isnothing(f_pos)) && (f_pos = "!h")
|
||||
# Set size
|
||||
attribs = ""
|
||||
width == nothing || (attribs = "width=$(md_length_to_latex(width,"\\linewidth"))")
|
||||
(attribs != "" && height != nothing) && (attribs *= ",")
|
||||
height == nothing || (attribs *= "height=$(md_length_to_latex(height,"\\paperheight"))")
|
||||
isnothing(width) || (attribs = "width=$(md_length_to_latex(width,"\\linewidth"))")
|
||||
(!isempty(attribs) && !isnothing(height)) && (attribs *= ",")
|
||||
isnothing(height) || (attribs *= "height=$(md_length_to_latex(height,"\\paperheight"))")
|
||||
|
||||
if f_env != nothing
|
||||
if !isnothing(f_env)
|
||||
result *= "\\begin{$f_env}"
|
||||
(f_pos != "") && (result *= "[$f_pos]")
|
||||
(!isempty(f_pos)) && (result *= "[$f_pos]")
|
||||
result *= "\n"
|
||||
end
|
||||
|
||||
|
@ -45,18 +45,18 @@ function formatfigures(chunk, docformat::TexFormat)
|
|||
end
|
||||
|
||||
# Figure environment
|
||||
if caption != nothing
|
||||
if !isnothing(caption)
|
||||
result *= string("\\center\n", "$figstring", "\\caption{$caption}\n")
|
||||
else
|
||||
result *= figstring
|
||||
end
|
||||
|
||||
if chunk.options[:label] != nothing && f_env != nothing
|
||||
if !isnothing(chunk.options[:label]) && !isnothing(f_env)
|
||||
label = chunk.options[:label]
|
||||
result *= "\\label{fig:$label}\n"
|
||||
end
|
||||
|
||||
if f_env != nothing
|
||||
if !isnothing(f_env)
|
||||
result *= "\\end{$f_env}\n"
|
||||
end
|
||||
|
||||
|
@ -66,7 +66,7 @@ end
|
|||
function md_length_to_latex(def, reference)
|
||||
if occursin("%", def)
|
||||
_def = tryparse(Float64, replace(def, "%" => ""))
|
||||
_def == nothing && return def
|
||||
isnothing(_def) && return def
|
||||
perc = round(_def / 100, digits = 2)
|
||||
return "$perc$reference"
|
||||
end
|
||||
|
|
|
@ -32,7 +32,7 @@ function formatfigures(chunk, docformat::Rest)
|
|||
figstring *= @sprintf(".. image:: %s\n :width: %s\n\n", fig, width)
|
||||
end
|
||||
|
||||
if caption != nothing
|
||||
if !isnothing(caption)
|
||||
result *= string(
|
||||
".. figure:: $(fignames[1])\n",
|
||||
" :width: $width\n\n",
|
||||
|
@ -77,7 +77,7 @@ function formatfigures(chunk, docformat::AsciiDoc)
|
|||
figstring *= @sprintf("image::%s[width=%s]\n", fig, width)
|
||||
end
|
||||
|
||||
if caption != nothing
|
||||
if !isnothing(caption)
|
||||
result *= string("image::$(fignames[1])", "[width=$width,", "title=\"$caption\"]")
|
||||
else
|
||||
result *= figstring
|
||||
|
|
|
@ -392,7 +392,7 @@ function collect_results(chunk::CodeChunk, fmt::ScriptResult)
|
|||
push!(result_chunks, rchunk)
|
||||
end
|
||||
end
|
||||
if content != ""
|
||||
if !isempty(content)
|
||||
startswith(content, "\n") || (content = "\n" * content)
|
||||
rchunk = CodeChunk(
|
||||
content,
|
||||
|
@ -429,7 +429,7 @@ function collect_results(chunk::CodeChunk, fmt::TermResult)
|
|||
push!(result_chunks, rchunk)
|
||||
end
|
||||
end
|
||||
if output != ""
|
||||
if !isempty(output)
|
||||
rchunk = CodeChunk(
|
||||
"",
|
||||
chunk.number,
|
||||
|
|
Loading…
Reference in New Issue