mirror of https://github.com/mpastell/Weave.jl
fixes #400
parent
78befc61b5
commit
e927495a62
|
@ -15,7 +15,7 @@ jobs:
|
||||||
fail-fast: false # don't stop CI even when one of them fails
|
fail-fast: false # don't stop CI even when one of them fails
|
||||||
matrix:
|
matrix:
|
||||||
version:
|
version:
|
||||||
- '1.4'
|
- '1.5'
|
||||||
os:
|
os:
|
||||||
- ubuntu-latest
|
- ubuntu-latest
|
||||||
- macOS-latest
|
- macOS-latest
|
||||||
|
|
|
@ -44,18 +44,14 @@ function render_chunk(docformat::WeaveFormat, chunk::CodeChunk)
|
||||||
|
|
||||||
chunk.content = render_code(docformat, chunk.content)
|
chunk.content = render_code(docformat, chunk.content)
|
||||||
|
|
||||||
if !chunk.options[:eval]
|
echo = chunk.options[:echo]
|
||||||
return if chunk.options[:echo]
|
|
||||||
string(docformat.codestart, '\n', chunk.content, docformat.codeend)
|
chunk.options[:eval] || return echo ? string(docformat.codestart, chunk.content, docformat.codeend) : ""
|
||||||
else
|
|
||||||
""
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
if chunk.options[:term]
|
if chunk.options[:term]
|
||||||
result = render_termchunk(docformat, chunk)
|
result = render_termchunk(docformat, chunk)
|
||||||
else
|
else
|
||||||
result = if chunk.options[:echo]
|
result = if echo
|
||||||
# Convert to output format and highlight (html, tex...) if needed
|
# Convert to output format and highlight (html, tex...) if needed
|
||||||
string(docformat.codestart, chunk.content, docformat.codeend, '\n')
|
string(docformat.codestart, chunk.content, docformat.codeend, '\n')
|
||||||
else
|
else
|
||||||
|
@ -126,7 +122,7 @@ render_output(docformat::WeaveFormat, output) = output
|
||||||
|
|
||||||
function render_termchunk(docformat::WeaveFormat, chunk)
|
function render_termchunk(docformat::WeaveFormat, chunk)
|
||||||
return if should_render(chunk)
|
return if should_render(chunk)
|
||||||
string(docformat.termstart, chunk.output, '\n', docformat.termend, '\n')
|
string(docformat.termstart, chunk.output, docformat.termend)
|
||||||
else
|
else
|
||||||
""
|
""
|
||||||
end
|
end
|
||||||
|
|
|
@ -15,8 +15,8 @@ render_termchunk(docformat::HTMLFormat, chunk) =
|
||||||
Base.@kwdef mutable struct WeaveHTML <: HTMLFormat
|
Base.@kwdef mutable struct WeaveHTML <: HTMLFormat
|
||||||
description = "Weave-style HTML"
|
description = "Weave-style HTML"
|
||||||
extension = "html"
|
extension = "html"
|
||||||
codestart = "\n"
|
codestart = '\n'
|
||||||
codeend = "\n"
|
codeend = '\n'
|
||||||
termstart = codestart
|
termstart = codestart
|
||||||
termend = codeend
|
termend = codeend
|
||||||
outputstart = "<pre class=\"output\">"
|
outputstart = "<pre class=\"output\">"
|
||||||
|
@ -127,12 +127,12 @@ end
|
||||||
Base.@kwdef mutable struct Pandoc2HTML <: HTMLFormat
|
Base.@kwdef mutable struct Pandoc2HTML <: HTMLFormat
|
||||||
description = "HTML via intermediate Pandoc Markdown (requires Pandoc 2)"
|
description = "HTML via intermediate Pandoc Markdown (requires Pandoc 2)"
|
||||||
extension = "md"
|
extension = "md"
|
||||||
codestart = "\n"
|
codestart = '\n'
|
||||||
codeend = "\n"
|
codeend = '\n'
|
||||||
termstart = codestart
|
termstart = codestart
|
||||||
termend = codeend
|
termend = codeend
|
||||||
outputstart = "\n"
|
outputstart = '\n'
|
||||||
outputend = "\n"
|
outputend = '\n'
|
||||||
mimetypes = ["image/png", "image/svg+xml", "image/jpg", "text/html", "text/markdown", "text/plain"]
|
mimetypes = ["image/png", "image/svg+xml", "image/jpg", "text/html", "text/markdown", "text/plain"]
|
||||||
fig_ext = ".png"
|
fig_ext = ".png"
|
||||||
out_width = nothing
|
out_width = nothing
|
||||||
|
|
|
@ -5,7 +5,7 @@ Base.@kwdef mutable struct GitHubMarkdown <: WeaveFormat
|
||||||
description = "GitHub Markdown"
|
description = "GitHub Markdown"
|
||||||
extension = "md"
|
extension = "md"
|
||||||
codestart = "```julia"
|
codestart = "```julia"
|
||||||
codeend = "```\n\n"
|
codeend = "```\n"
|
||||||
termstart = codestart
|
termstart = codestart
|
||||||
termend = codeend
|
termend = codeend
|
||||||
outputstart = "```"
|
outputstart = "```"
|
||||||
|
@ -51,7 +51,7 @@ Base.@kwdef mutable struct Hugo <: WeaveFormat
|
||||||
description = "Hugo Markdown (using shortcodes)"
|
description = "Hugo Markdown (using shortcodes)"
|
||||||
extension = "md"
|
extension = "md"
|
||||||
codestart = "```julia"
|
codestart = "```julia"
|
||||||
codeend = "```\n\n"
|
codeend = "```\n"
|
||||||
termstart = codestart
|
termstart = codestart
|
||||||
termend = codeend
|
termend = codeend
|
||||||
outputstart = "```"
|
outputstart = "```"
|
||||||
|
@ -89,7 +89,7 @@ Base.@kwdef mutable struct MultiMarkdown <: WeaveFormat
|
||||||
description = "MultiMarkdown"
|
description = "MultiMarkdown"
|
||||||
extension = "md"
|
extension = "md"
|
||||||
codestart = "```julia"
|
codestart = "```julia"
|
||||||
codeend = "```\n\n"
|
codeend = "```\n"
|
||||||
termstart = codestart
|
termstart = codestart
|
||||||
termend = codeend
|
termend = codeend
|
||||||
outputstart = "```"
|
outputstart = "```"
|
||||||
|
@ -143,7 +143,7 @@ Base.@kwdef mutable struct Rest <: WeaveFormat
|
||||||
description = "reStructuredText and Sphinx"
|
description = "reStructuredText and Sphinx"
|
||||||
extension = "rst"
|
extension = "rst"
|
||||||
codestart = ".. code-block:: julia\n"
|
codestart = ".. code-block:: julia\n"
|
||||||
codeend = "\n\n"
|
codeend = "\n"
|
||||||
termstart = codestart
|
termstart = codestart
|
||||||
termend = codeend
|
termend = codeend
|
||||||
outputstart = "::\n"
|
outputstart = "::\n"
|
||||||
|
@ -190,7 +190,7 @@ Base.@kwdef mutable struct AsciiDoc <: WeaveFormat
|
||||||
description = "AsciiDoc"
|
description = "AsciiDoc"
|
||||||
extension = "txt"
|
extension = "txt"
|
||||||
codestart = "[source,julia]\n--------------------------------------"
|
codestart = "[source,julia]\n--------------------------------------"
|
||||||
codeend = "--------------------------------------\n\n"
|
codeend = "--------------------------------------\n"
|
||||||
termstart = codestart
|
termstart = codestart
|
||||||
termend = codeend
|
termend = codeend
|
||||||
outputstart = "--------------------------------------"
|
outputstart = "--------------------------------------"
|
||||||
|
|
|
@ -37,7 +37,7 @@ Base.@kwdef mutable struct Pandoc <: PandocFormat
|
||||||
description = "Pandoc Markdown"
|
description = "Pandoc Markdown"
|
||||||
extension = "md"
|
extension = "md"
|
||||||
codestart = "~~~~{.julia}"
|
codestart = "~~~~{.julia}"
|
||||||
codeend = "~~~~~~~~~~~~~\n\n"
|
codeend = "~~~~~~~~~~~~~\n"
|
||||||
termstart = codestart
|
termstart = codestart
|
||||||
termend = codeend
|
termend = codeend
|
||||||
outputstart = "~~~~"
|
outputstart = "~~~~"
|
||||||
|
@ -60,7 +60,7 @@ Base.@kwdef mutable struct Pandoc2PDF <: PandocFormat
|
||||||
description = "PDF via intermediate Pandoc Markdown"
|
description = "PDF via intermediate Pandoc Markdown"
|
||||||
extension = "md"
|
extension = "md"
|
||||||
codestart = "~~~~{.julia}"
|
codestart = "~~~~{.julia}"
|
||||||
codeend = "~~~~~~~~~~~~~\n\n"
|
codeend = "~~~~~~~~~~~~~\n"
|
||||||
termstart = codestart
|
termstart = codestart
|
||||||
termend = codeend
|
termend = codeend
|
||||||
outputstart = "~~~~"
|
outputstart = "~~~~"
|
||||||
|
|
|
@ -353,11 +353,9 @@ function collect_results(chunk::CodeChunk)
|
||||||
content = ""
|
content = ""
|
||||||
result_chunks = CodeChunk[]
|
result_chunks = CodeChunk[]
|
||||||
for r in chunk.result
|
for r in chunk.result
|
||||||
# Check if there is any output from chunk
|
|
||||||
if strip(r.stdout) == "" && isempty(r.figures) && strip(r.rich_output) == ""
|
|
||||||
content *= r.code
|
content *= r.code
|
||||||
else
|
# Check if there is any output from chunk
|
||||||
content = "\n" * content * r.code
|
if any(!isempty ∘ strip, (r.stdout, r.rich_output)) || !isempty(r.figures)
|
||||||
rchunk = CodeChunk(
|
rchunk = CodeChunk(
|
||||||
content,
|
content,
|
||||||
chunk.number,
|
chunk.number,
|
||||||
|
@ -365,15 +363,14 @@ function collect_results(chunk::CodeChunk)
|
||||||
chunk.optionstring,
|
chunk.optionstring,
|
||||||
copy(chunk.options),
|
copy(chunk.options),
|
||||||
)
|
)
|
||||||
content = ""
|
|
||||||
rchunk.figures = r.figures
|
rchunk.figures = r.figures
|
||||||
rchunk.output = r.stdout
|
rchunk.output = r.stdout
|
||||||
rchunk.rich_output = r.rich_output
|
rchunk.rich_output = r.rich_output
|
||||||
push!(result_chunks, rchunk)
|
push!(result_chunks, rchunk)
|
||||||
|
content = ""
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
if !isempty(content)
|
if !isempty(content)
|
||||||
startswith(content, "\n") || (content = "\n" * content)
|
|
||||||
rchunk = CodeChunk(
|
rchunk = CodeChunk(
|
||||||
content,
|
content,
|
||||||
chunk.number,
|
chunk.number,
|
||||||
|
|
Loading…
Reference in New Issue