pull/401/head
Shuhei Kadowaki 2020-10-03 04:21:19 +09:00
parent 78befc61b5
commit e927495a62
6 changed files with 22 additions and 29 deletions

View File

@ -15,7 +15,7 @@ jobs:
fail-fast: false # don't stop CI even when one of them fails
matrix:
version:
- '1.4'
- '1.5'
os:
- ubuntu-latest
- macOS-latest

View File

@ -44,18 +44,14 @@ function render_chunk(docformat::WeaveFormat, chunk::CodeChunk)
chunk.content = render_code(docformat, chunk.content)
if !chunk.options[:eval]
return if chunk.options[:echo]
string(docformat.codestart, '\n', chunk.content, docformat.codeend)
else
""
end
end
echo = chunk.options[:echo]
chunk.options[:eval] || return echo ? string(docformat.codestart, chunk.content, docformat.codeend) : ""
if chunk.options[:term]
result = render_termchunk(docformat, chunk)
else
result = if chunk.options[:echo]
result = if echo
# Convert to output format and highlight (html, tex...) if needed
string(docformat.codestart, chunk.content, docformat.codeend, '\n')
else
@ -126,7 +122,7 @@ render_output(docformat::WeaveFormat, output) = output
function render_termchunk(docformat::WeaveFormat, chunk)
return if should_render(chunk)
string(docformat.termstart, chunk.output, '\n', docformat.termend, '\n')
string(docformat.termstart, chunk.output, docformat.termend)
else
""
end

View File

@ -15,8 +15,8 @@ render_termchunk(docformat::HTMLFormat, chunk) =
Base.@kwdef mutable struct WeaveHTML <: HTMLFormat
description = "Weave-style HTML"
extension = "html"
codestart = "\n"
codeend = "\n"
codestart = '\n'
codeend = '\n'
termstart = codestart
termend = codeend
outputstart = "<pre class=\"output\">"
@ -127,12 +127,12 @@ end
Base.@kwdef mutable struct Pandoc2HTML <: HTMLFormat
description = "HTML via intermediate Pandoc Markdown (requires Pandoc 2)"
extension = "md"
codestart = "\n"
codeend = "\n"
codestart = '\n'
codeend = '\n'
termstart = codestart
termend = codeend
outputstart = "\n"
outputend = "\n"
outputstart = '\n'
outputend = '\n'
mimetypes = ["image/png", "image/svg+xml", "image/jpg", "text/html", "text/markdown", "text/plain"]
fig_ext = ".png"
out_width = nothing

View File

@ -5,7 +5,7 @@ Base.@kwdef mutable struct GitHubMarkdown <: WeaveFormat
description = "GitHub Markdown"
extension = "md"
codestart = "```julia"
codeend = "```\n\n"
codeend = "```\n"
termstart = codestart
termend = codeend
outputstart = "```"
@ -51,7 +51,7 @@ Base.@kwdef mutable struct Hugo <: WeaveFormat
description = "Hugo Markdown (using shortcodes)"
extension = "md"
codestart = "```julia"
codeend = "```\n\n"
codeend = "```\n"
termstart = codestart
termend = codeend
outputstart = "```"
@ -89,7 +89,7 @@ Base.@kwdef mutable struct MultiMarkdown <: WeaveFormat
description = "MultiMarkdown"
extension = "md"
codestart = "```julia"
codeend = "```\n\n"
codeend = "```\n"
termstart = codestart
termend = codeend
outputstart = "```"
@ -143,7 +143,7 @@ Base.@kwdef mutable struct Rest <: WeaveFormat
description = "reStructuredText and Sphinx"
extension = "rst"
codestart = ".. code-block:: julia\n"
codeend = "\n\n"
codeend = "\n"
termstart = codestart
termend = codeend
outputstart = "::\n"
@ -190,7 +190,7 @@ Base.@kwdef mutable struct AsciiDoc <: WeaveFormat
description = "AsciiDoc"
extension = "txt"
codestart = "[source,julia]\n--------------------------------------"
codeend = "--------------------------------------\n\n"
codeend = "--------------------------------------\n"
termstart = codestart
termend = codeend
outputstart = "--------------------------------------"

View File

@ -37,7 +37,7 @@ Base.@kwdef mutable struct Pandoc <: PandocFormat
description = "Pandoc Markdown"
extension = "md"
codestart = "~~~~{.julia}"
codeend = "~~~~~~~~~~~~~\n\n"
codeend = "~~~~~~~~~~~~~\n"
termstart = codestart
termend = codeend
outputstart = "~~~~"
@ -60,7 +60,7 @@ Base.@kwdef mutable struct Pandoc2PDF <: PandocFormat
description = "PDF via intermediate Pandoc Markdown"
extension = "md"
codestart = "~~~~{.julia}"
codeend = "~~~~~~~~~~~~~\n\n"
codeend = "~~~~~~~~~~~~~\n"
termstart = codestart
termend = codeend
outputstart = "~~~~"

View File

@ -353,11 +353,9 @@ function collect_results(chunk::CodeChunk)
content = ""
result_chunks = CodeChunk[]
for r in chunk.result
content *= r.code
# Check if there is any output from chunk
if strip(r.stdout) == "" && isempty(r.figures) && strip(r.rich_output) == ""
content *= r.code
else
content = "\n" * content * r.code
if any(!isempty strip, (r.stdout, r.rich_output)) || !isempty(r.figures)
rchunk = CodeChunk(
content,
chunk.number,
@ -365,15 +363,14 @@ function collect_results(chunk::CodeChunk)
chunk.optionstring,
copy(chunk.options),
)
content = ""
rchunk.figures = r.figures
rchunk.output = r.stdout
rchunk.rich_output = r.rich_output
push!(result_chunks, rchunk)
content = ""
end
end
if !isempty(content)
startswith(content, "\n") || (content = "\n" * content)
rchunk = CodeChunk(
content,
chunk.number,