remove format dict - make everything a field of format <: WeaveFormat directly

pull/350/head
Jonas Isensee 2020-05-31 09:29:26 +02:00
parent 6e99822905
commit 770496b3af
11 changed files with 270 additions and 261 deletions

View File

@ -37,7 +37,7 @@ take2string!(io) = String(take!(io))
List supported output formats
"""
list_out_formats(io = stdout) = for (k, v) in FORMATS; println(io, string(k, ": ", v.formatdict[:description])); end
list_out_formats(io = stdout) = for (k, v) in FORMATS; println(io, string(k, ": ", v.description)); end
"""
tangle(source::AbstractString; kwargs...)
@ -197,7 +197,7 @@ function weave(
keep_unicode = get(weave_options, "keep_unicode", keep_unicode)
end
get!(doc.format.formatdict, :keep_unicode, keep_unicode)
doc.format.keep_unicode = doc.format.keep_unicode | keep_unicode
rendered = format(doc, template, highlight_theme; css = css)
outname = get_outname(out_path, doc)

View File

@ -4,7 +4,7 @@ using Markdown, .WeaveMarkdown
mutable struct Report <: AbstractDisplay
cwd::AbstractString
basename::AbstractString
formatdict::Dict{Symbol,Any}
format::WeaveFormat
pending_code::AbstractString
cur_result::AbstractString
rich_output::AbstractString
@ -18,11 +18,11 @@ mutable struct Report <: AbstractDisplay
throw_errors::Bool
end
function Report(cwd, basename, formatdict, mimetypes, throw_errors)
function Report(cwd, basename, format, mimetypes, throw_errors)
Report(
cwd,
basename,
formatdict,
format,
"",
"",
"",

View File

@ -6,15 +6,7 @@ using REPL.REPLCompletions: latex_symbols
function format(doc, template = nothing, highlight_theme = nothing; css = nothing)
docformat = doc.format
# This could instead be made defaults in Base.@kwdef type declaration
# Complete format dictionaries with defaults
get!(docformat.formatdict, :termstart, docformat.formatdict[:codestart])
get!(docformat.formatdict, :termend, docformat.formatdict[:codeend])
get!(docformat.formatdict, :out_width, nothing)
get!(docformat.formatdict, :out_height, nothing)
get!(docformat.formatdict, :fig_pos, nothing)
get!(docformat.formatdict, :fig_env, nothing)
docformat.formatdict[:highlight_theme] = get_highlight_theme(highlight_theme)
docformat.highlight_theme = get_highlight_theme(highlight_theme)
restore_header!(doc)

View File

@ -7,24 +7,6 @@
abstract type WeaveFormat end
const FORMATS = Dict{String,WeaveFormat}()
macro define_format(ex)
return if ex isa Symbol
quote
struct $(ex) <: $(WeaveFormat)
formatdict::Dict{Symbol,Any}
end
end
elseif Meta.isexpr(ex, :<:)
type_name, supertype = ex.args
quote
@assert $(esc(supertype)) <: $(WeaveFormat) "$($(esc(supertype))) should be subtype of WeaveFormat"
struct $(type_name) <: $(esc(supertype))
formatdict::Dict{Symbol,Any}
end
end
else
error("@define_format expects T or T<:S expression")
end
end
# TODO: do some assertion for necessary fields of `formatdict`
# TODO: do some assertion for necessary fields of `format`
register_format!(format_name::AbstractString, format::WeaveFormat) = push!(FORMATS, format_name => format)
register_format!(_,format) = error("Format needs to be a subtype of WeaveFormat.")

View File

@ -40,24 +40,23 @@ end
addlines(op, inline) = inline.ctype === :line ? string('\n', op, '\n') : op
function format_chunk(chunk::CodeChunk, docformat)
formatdict = docformat.formatdict
# Fill undefined options with format specific defaults
isnothing(chunk.options[:out_width]) && (chunk.options[:out_width] = formatdict[:out_width])
isnothing(chunk.options[:fig_pos]) && (chunk.options[:fig_pos] = formatdict[:fig_pos])
isnothing(chunk.options[:out_width]) && (chunk.options[:out_width] = docformat.out_width)
isnothing(chunk.options[:fig_pos]) && (chunk.options[:fig_pos] = docformat.fig_pos)
# Only use floats if chunk has caption or sets fig_env
if !isnothing(chunk.options[:fig_cap]) && isnothing(chunk.options[:fig_env])
(chunk.options[:fig_env] = formatdict[:fig_env])
(chunk.options[:fig_env] = docformat.fig_env)
end
haskey(formatdict, :indent) && (chunk.content = indent(chunk.content, formatdict[:indent]))
hasfield(docformat, :indent) && (chunk.content = indent(chunk.content, docformat.indent))
chunk.content = format_code(chunk.content, docformat)
if !chunk.options[:eval]
return if chunk.options[:echo]
string(formatdict[:codestart], '\n', chunk.content, formatdict[:codeend])
string(docformat.codestart, '\n', chunk.content, docformat.codeend)
else
""
end
@ -68,7 +67,7 @@ function format_chunk(chunk::CodeChunk, docformat)
else
result = if chunk.options[:echo]
# Convert to output format and highlight (html, tex...) if needed
string(formatdict[:codestart], chunk.content, formatdict[:codeend], '\n')
string(docformat.codestart, chunk.content, docformat.codeend, '\n')
else
""
end
@ -88,11 +87,11 @@ function format_chunk(chunk::CodeChunk, docformat)
chunk.output = format_output(chunk.output, docformat)
end
if haskey(formatdict, :indent)
chunk.output = indent(chunk.output, formatdict[:indent])
if hasfield(docformat, :indent)
chunk.output = indent(chunk.output, docformat.indent)
end
strip(chunk.output) "" && (
result *= "$(formatdict[:outputstart])$(chunk.output)\n$(formatdict[:outputend])\n"
result *= "$(docformat.outputstart)$(chunk.output)\n$(docformat.outputend)\n"
)
strip(chunk.rich_output) "" && (result *= chunk.rich_output * '\n')
end
@ -131,8 +130,7 @@ end
function format_termchunk(chunk, docformat)
return if should_render(chunk)
fd = docformat.formatdict
string(fd[:termstart], chunk.output, '\n', fd[:termend], '\n')
string(docformat.termstart, chunk.output, '\n', docformat.termend, '\n')
else
""
end

View File

@ -2,43 +2,47 @@
# ----
abstract type HTMLFormat <: WeaveFormat end
@define_format JMarkdown2HTML <: HTMLFormat
register_format!("md2html", JMarkdown2HTML(Dict(
:description => "Julia markdown to html",
:codestart => "\n",
:codeend => "\n",
:outputstart => "<pre class=\"output\">",
:outputend => "</pre>\n",
:fig_ext => ".png",
:mimetypes => [
"image/png",
"image/jpg",
"image/svg+xml",
"text/html",
"text/markdown",
"text/plain",
],
:extension => "html",
)))
mutable struct JMarkdown2HTML <: HTMLFormat
description = "Julia markdown to html"
codestart = "\n"
codeend = "\n"
outputstart = "<pre class=\"output\">"
outputend = "</pre>\n"
fig_ext = ".png"
mimetypes = ["image/png", "image/jpg", "image/svg+xml",
"text/html", "text/markdown", "text/plain"]
keep_unicode = false
extension = "html"
termstart = codestart
termend = codeend
out_width = nothing
out_height = nothing
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
end
register_format!("md2html", JMarkdown2HTML())
@define_format Pandoc2HTML <: HTMLFormat
register_format!("pandoc2html", Pandoc2HTML(Dict(
:description => "Markdown to HTML (requires Pandoc 2)",
:codestart => "\n",
:codeend => "\n",
:outputstart => "\n",
:outputend => "\n",
:fig_ext => ".png",
:extension => "md",
:mimetypes => [
"image/png",
"image/svg+xml",
"image/jpg",
"text/html",
"text/markdown",
"text/plain",
],
)))
mutable struct Pandoc2HTML <: HTMLFormat
description = "Markdown to HTML (requires Pandoc 2)"
codestart = "\n"
codeend = "\n"
outputstart = "\n"
outputend = "\n"
fig_ext = ".png"
extension = "md"
mimetypes = ["image/png", "image/svg+xml", "image/jpg",
"text/html", "text/markdown", "text/plain"]
keep_unicode = false
termstart = codestart
termend = codeend
out_width = nothing
out_height = nothing
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
end
register_format!("pandoc2html", Pandoc2HTML())
function render_doc(::JMarkdown2HTML, body, doc, template, css, highlight_theme)
@ -81,10 +85,10 @@ end
format_output(result, docformat::JMarkdown2HTML) = Markdown.htmlesc(result)
format_code(code, docformat::HTMLFormat) =
highlight_code(MIME("text/html"), code, docformat.formatdict[:highlight_theme])
highlight_code(MIME("text/html"), code, docformat.highlight_theme)
format_termchunk(chunk, docformat::HTMLFormat) =
should_render(chunk) ? highlight_term(MIME("text/html"), chunk.output, docformat.formatdict[:highlight_theme]) : ""
should_render(chunk) ? highlight_term(MIME("text/html"), chunk.output, docformat.highlight_theme) : ""
formatfigures(chunk, docformat::Pandoc2HTML) = formatfigures(chunk, pandoc)

View File

@ -1,44 +1,94 @@
abstract type MarkdownFormat end
# markdown
# --------
@define_format GitHubMarkdown
register_format!("github", GitHubMarkdown(Dict(
:description => "GitHub markdown",
:codestart => "````julia",
:codeend => "````\n\n",
:outputstart => "````",
:outputend => "````\n\n",
:fig_ext => ".png",
:extension => "md",
:mimetypes =>
["image/png", "image/svg+xml", "image/jpg", "text/markdown", "text/plain"],
)))
@define_format GitHubMarkdown <: MarkdownFormat
description = "GitHub markdown",
codestart = "````julia",
codeend = "````\n\n",
outputstart = "````",
outputend = "````\n\n",
fig_ext = ".png",
extension = "md",
mimetypes =
["image/png", "image/svg+xml", "image/jpg", "text/markdown", "text/plain"]
keep_unicode = false
termstart = codestart
termend = codeend
out_width = nothing
out_height = nothing
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
end
register_format!("github", GitHubMarkdown())
@define_format Hugo
register_format!("hugo", Hugo(Dict(
:description => "Hugo markdown (using shortcodes)",
:codestart => "````julia",
:codeend => "````\n\n",
:outputstart => "````",
:outputend => "````\n\n",
:fig_ext => ".png",
:extension => "md",
:uglyURLs => false, # if `false`, prepend figure path by `..`
)))
mutable struct Hugo <: MarkdownFormat
description = "Hugo markdown (using shortcodes)"
codestart = "````julia"
codeend = "````\n\n"
outputstart = "````"
outputend = "````\n\n"
fig_ext = ".png"
extension = "md"
uglyURLs = false # if `false`, prepend figure path by `..`
keep_unicode = false
termstart = codestart
termend = codeend
out_width = nothing
out_height = nothing
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
end
register_format!("hugo", Hugo())
@define_format MultiMarkdown
register_format!("multimarkdown", MultiMarkdown(Dict(
:description => "MultiMarkdown",
:codestart => "````julia",
:codeend => "````\n\n",
:outputstart => "````",
:outputend => "````\n\n",
:fig_ext => ".png",
:extension => "md",
)))
mutable struct MultiMarkdown <: MarkdownFormat
description = "MultiMarkdown"
codestart = "````julia"
codeend = "````\n\n"
outputstart = "````"
outputend = "````\n\n"
fig_ext = ".png"
extension = "md"
keep_unicode = false
termstart = codestart
termend = codeend
out_width = nothing
out_height = nothing
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
end
register_format!("multimarkdown", MultiMarkdown())
# pandoc
# ------
mutable struct Pandoc <: MarkdownFormat
description = "Pandoc markdown"
codestart = "~~~~{.julia}"
codeend = "~~~~~~~~~~~~~\n\n"
outputstart = "~~~~"
outputend = "~~~~\n\n"
fig_ext = ".png"
out_width = nothing
extension = "md"
# Prefer png figures for markdown conversion, svg doesn't work with latex
mimetypes = ["image/png", "image/jpg", "image/svg+xml",
"text/markdown", "text/plain"]
keep_unicode = false
termstart = codestart
termend = codeend
out_width = nothing
out_height = nothing
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
end
register_format!("pandoc", Pandoc())
register_format!("pandoc2pdf", Pandoc())
function formatfigures(chunk, docformat::GitHubMarkdown)
@ -64,7 +114,7 @@ function formatfigures(chunk, docformat::GitHubMarkdown)
end
function formatfigures(chunk, docformat::Hugo)
relpath = docformat.formatdict[:uglyURLs] ? "" : ".."
relpath = docformat.uglyURLs ? "" : ".."
mapreduce(*, enumerate(chunk.figures), init = "") do (index, fig)
if index > 1
@warn("Only the first figure gets a caption.")

View File

@ -3,88 +3,80 @@
abstract type TexFormat <: WeaveFormat end
@define_format JMarkdown2tex <: TexFormat
let t = JMarkdown2tex(Dict(
:description => "Julia markdown to latex",
:codestart => "",
:codeend => "",
:outputstart => "\\begin{lstlisting}",
:outputend => "\\end{lstlisting}\n",
:fig_ext => ".pdf",
:extension => "tex",
:out_width => "\\linewidth",
:mimetypes => [
"application/pdf",
"image/png",
"image/jpg",
"text/latex",
"text/markdown",
"text/plain",
],
:keep_unicode => false,
))
register_format!("md2pdf", t)
register_format!("md2tex", t)
Base.@kwdef mutable struct JMarkdown2tex <: TexFormat
description = "Julia markdown to latex"
codestart = ""
codeend = ""
outputstart = "\\begin{lstlisting}"
outputend = "\\end{lstlisting}\n"
fig_ext = ".pdf"
extension = "tex"
out_width = "\\linewidth",
mimetypes = ["application/pdf", "image/png", "image/jpg",
"text/latex", "text/markdown", "text/plain"]
keep_unicode = false
termstart = codestart
termend = codeend
out_width = nothing
out_height = nothing
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
end
register_format!("md2tex", JMarkdown2tex())
# Base.@kwdef mutable struct JMarkdown2tex <: TexFormat
# codestart = ""
# codeend = ""
# outputstart = "\\begin{lstlisting}",
# outputend = "\\end{lstlisting}\n",
# fig_ext = ".pdf",
# extension = "tex",
# out_width = "\\linewidth",
# mimetypes => [
# "application/pdf",
# "image/png",
# "image/jpg",
# "text/latex",
# "text/markdown",
# "text/plain",
# ],
# keep_unicode => false,
# end
# register_format!("md2tex", JMarkdown2tex())
mutable struct Tex <: TexFormat
description = "Latex with custom code environments"
codestart = "\\begin{juliacode}"
codeend = "\\end{juliacode}"
outputstart = "\\begin{juliaout}"
outputend = "\\end{juliaout}"
termstart = "\\begin{juliaterm}"
termend = "\\end{juliaterm}"
fig_ext = ".pdf"
extension = "tex"
out_width = "\\linewidth"
fig_env = "figure"
fig_pos = "htpb"
mimetypes = ["application/pdf", "image/png", "text/latex", "text/plain"]
keep_unicode = false
termstart = codestart
termend = codeend
out_width = nothing
out_height = nothing
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
end
register_format!("tex", Tex())
@define_format Tex <: TexFormat
register_format!("tex", Tex(Dict(
:description => "Latex with custom code environments",
:codestart => "\\begin{juliacode}",
:codeend => "\\end{juliacode}",
:outputstart => "\\begin{juliaout}",
:outputend => "\\end{juliaout}",
:termstart => "\\begin{juliaterm}",
:termend => "\\end{juliaterm}",
:fig_ext => ".pdf",
:extension => "tex",
:out_width => "\\linewidth",
:fig_env => "figure",
:fig_pos => "htpb",
:mimetypes => ["application/pdf", "image/png", "text/latex", "text/plain"],
:keep_unicode => false,
)))
@define_format TexMinted <: TexFormat
register_format!("texminted", TexMinted(Dict(
:description => "Latex using minted for highlighting",
:codestart =>
"\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}",
:codeend => "\\end{minted}",
:outputstart =>
"\\begin{minted}[fontsize=\\small, xleftmargin=0.5em, mathescape, frame = leftline]{text}",
:outputend => "\\end{minted}",
:termstart =>
"\\begin{minted}[fontsize=\\footnotesize, xleftmargin=0.5em, mathescape]{jlcon}",
:termend => "\\end{minted}",
:fig_ext => ".pdf",
:extension => "tex",
:out_width => "\\linewidth",
:fig_env => "figure",
:fig_pos => "htpb",
:mimetypes => ["application/pdf", "image/png", "text/latex", "text/plain"],
:keep_unicode => false,
)))
mutable struct TexMinted <: TexFormat
description = "Latex using minted for highlighting"
codestart =
"\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}"
codeend = "\\end{minted}"
outputstart =
"\\begin{minted}[fontsize=\\small, xleftmargin=0.5em, mathescape, frame = leftline]{text}"
outputend = "\\end{minted}"
termstart =
"\\begin{minted}[fontsize=\\footnotesize, xleftmargin=0.5em, mathescape]{jlcon}"
termend = "\\end{minted}"
fig_ext = ".pdf"
extension = "tex"
out_width = "\\linewidth"
fig_env = "figure"
fig_pos = "htpb"
mimetypes = ["application/pdf", "image/png", "text/latex", "text/plain"]
keep_unicode = false
termstart = codestart
termend = codeend
out_width = nothing
out_height = nothing
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
end
register_format!("texminted", TexMinted())
@ -121,7 +113,7 @@ function format_chunk(chunk::DocChunk, docformat::TexFormat)
end
clear_buffer_and_format!(io, out, WeaveMarkdown.latex)
out = take2string!(out)
return docformat.formatdict[:keep_unicode] ? out : uc2tex(out)
return docformat.keep_unicode ? out : uc2tex(out)
end
function format_output(result, docformat::TexFormat)
@ -131,14 +123,14 @@ function format_output(result, docformat::TexFormat)
Highlights.Format.escape(io, MIME("text/latex"), x, charescape = true),
result,
)
docformat.formatdict[:keep_unicode] || return uc2tex(result_escaped, true)
docformat.keep_unicode || return uc2tex(result_escaped, true)
return result_escaped
end
# return "\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}\n$result\n\\end{minted}\n"
function format_code(code, docformat::TexFormat)
ret = highlight_code(MIME("text/latex"), code, docformat.formatdict[:highlight_theme])
docformat.formatdict[:keep_unicode] || return uc2tex(ret)
ret = highlight_code(MIME("text/latex"), code, docformat.highlight_theme)
docformat.keep_unicode || return uc2tex(ret)
return ret
end
@ -158,7 +150,7 @@ end
# return "\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}\n$result\n\\end{minted}\n"
format_termchunk(chunk, docformat::TexFormat) =
should_render(chunk) ? highlight_term(MIME("text/latex"), chunk.output, docformat.formatdict[:highlight_theme]) : ""
should_render(chunk) ? highlight_term(MIME("text/latex"), chunk.output, docformat.highlight_theme]) : ""
function formatfigures(chunk, docformat::TexFormat)

View File

@ -1,59 +1,51 @@
# pandoc
# ------
@define_format Pandoc
let p = Pandoc(Dict(
:description => "Pandoc markdown",
:codestart => "~~~~{.julia}",
:codeend => "~~~~~~~~~~~~~\n\n",
:outputstart => "~~~~",
:outputend => "~~~~\n\n",
:fig_ext => ".png",
:out_width => nothing,
:extension => "md",
# Prefer png figures for markdown conversion, svg doesn't work with latex
:mimetypes =>
["image/png", "image/jpg", "image/svg+xml", "text/markdown", "text/plain"],
))
register_format!("pandoc", p)
register_format!("pandoc2pdf", p)
end
# Rest
# ----
@define_format Rest
register_format!("rst", Rest(Dict(
:description => "reStructuredText and Sphinx",
:codestart => ".. code-block:: julia\n",
:codeend => "\n\n",
:outputstart => "::\n",
:outputend => "\n\n",
:indent => 4,
:fig_ext => ".png",
:extension => "rst",
:out_width => "15 cm",
)))
mutable struct Rest <: WeaveFormat
description = "reStructuredText and Sphinx"
codestart = ".. code-block:: julia\n"
codeend = "\n\n"
outputstart = "::\n"
outputend = "\n\n"
indent = 4
fig_ext = ".png"
extension = "rst"
out_width = "15 cm"
keep_unicode = false
termstart = codestart
termend = codeend
out_width = nothing
out_height = nothing
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
end
register_format!("rst", Rest())
# Ansii
# -----
# asciidoc -b html5 -a source-highlighter=pygments ...
@define_format AsciiDoc
register_format!("asciidoc", AsciiDoc(Dict(
:description => "AsciiDoc",
:codestart => "[source,julia]\n--------------------------------------",
:codeend => "--------------------------------------\n\n",
:outputstart => "--------------------------------------",
:outputend => "--------------------------------------\n\n",
:fig_ext => ".png",
:extension => "txt",
:out_width => "600",
)))
mutable struct AsciiDoc <: WeaveFormat
description = "AsciiDoc"
codestart = "[source,julia]\n--------------------------------------"
codeend = "--------------------------------------\n\n"
outputstart = "--------------------------------------"
outputend = "--------------------------------------\n\n"
fig_ext = ".png"
extension = "txt"
out_width = "600"
keep_unicode = false
termstart = codestart
termend = codeend
out_width = nothing
out_height = nothing
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
end
register_format!("asciidoc", AsciiDoc())

View File

@ -64,9 +64,9 @@ function run_doc(
isnothing(mod) && (mod = sandbox = Core.eval(Main, :(module $(gensym(:WeaveSandBox)) end))::Module)
@eval mod WEAVE_ARGS = $args
mimetypes = get(doc.format.formatdict, :mimetypes, default_mime_types)
mimetypes = doc.format.mimetypes
report = Report(doc.cwd, doc.basename, doc.format.formatdict, mimetypes, throw_errors)
report = Report(doc.cwd, doc.basename, doc.format, mimetypes, throw_errors)
pushdisplay(report)
try
if cache !== :off && cache !== :refresh
@ -283,8 +283,8 @@ function eval_chunk(chunk::CodeChunk, report::Report, SandBox::Module)
report.fignum = 1
report.cur_chunk = chunk
if haskey(report.formatdict, :out_width) && isnothing(chunk.options[:out_width])
chunk.options[:out_width] = report.formatdict[:out_width]
if hasfield(report.format, :out_width) && isnothing(chunk.options[:out_width])
chunk.options[:out_width] = report.format.out_width
end
chunk.result = run_code(chunk, report, SandBox)
@ -370,13 +370,13 @@ end
"""Get output file name based on out_path"""
function get_outname(out_path::Symbol, doc::WeaveDoc; ext = nothing)
isnothing(ext) && (ext = doc.format.formatdict[:extension])
isnothing(ext) && (ext = doc.format.extension)
outname = "$(doc.cwd)/$(doc.basename).$ext"
end
"""Get output file name based on out_path"""
function get_outname(out_path::AbstractString, doc::WeaveDoc; ext = nothing)
isnothing(ext) && (ext = doc.format.formatdict[:extension])
isnothing(ext) && (ext = doc.format.extension)
splitted = splitext(out_path)
if (splitted[2]) == ""
outname = "$(doc.cwd)/$(doc.basename).$ext"
@ -386,9 +386,8 @@ function get_outname(out_path::AbstractString, doc::WeaveDoc; ext = nothing)
end
function set_rc_params(doc::WeaveDoc, fig_path, fig_ext)
formatdict = doc.format.formatdict
if isnothing(fig_ext)
doc.chunk_defaults[:fig_ext] = formatdict[:fig_ext]
doc.chunk_defaults[:fig_ext] = doc.format.fig_ext
else
doc.chunk_defaults[:fig_ext] = fig_ext
end

View File

@ -26,7 +26,7 @@ parsed = Weave.WeaveDoc("documents/chunk_options.noweb")
doc = run_doc(parsed, doctype = "md2html")
c_check = "<pre class='hljl'>\n<span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-p'>[</span><span class='hljl-ni'>12</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-ni'>10</span><span class='hljl-p'>]</span><span class='hljl-t'>\n</span><span class='hljl-nf'>println</span><span class='hljl-p'>(</span><span class='hljl-n'>y</span><span class='hljl-p'>)</span>\n</pre>\n"
doc.format.formatdict[:highlight_theme] = DefaultTheme
doc.format.highlight_theme = DefaultTheme
c = Weave.format_code(doc.chunks[3].content, doc.format)
@test c_check == c
@ -39,7 +39,7 @@ parsed = Weave.WeaveDoc("documents/chunk_options.noweb")
doc = run_doc(parsed, doctype = "md2tex")
c_check = "\\begin{lstlisting}\n(*@\\HLJLnf{println}@*)(*@\\HLJLp{(}@*)(*@\\HLJLn{x}@*)(*@\\HLJLp{)}@*)\n\\end{lstlisting}\n"
doc.format.formatdict[:highlight_theme] = DefaultTheme
doc.format.highlight_theme = DefaultTheme
c = Weave.format_code(doc.chunks[4].content, doc.format)
@test c_check == c
@ -93,7 +93,7 @@ fmt = deepcopy(Weave.FORMATS["md2tex"])
f = Weave.format_chunk(chunk, fmt)
@test f == "\\section{Test chunk}\n\\ensuremath{\\alpha}\n\n"
fmt.formatdict[:keep_unicode] = true
fmt.keep_unicode = true
f = Weave.format_chunk(chunk, fmt)
@test f == "\\section{Test chunk}\nα\n\n"
@ -109,7 +109,7 @@ doc = Weave.format(doc)
@test !occursin("α", doc)
doc = mock_doc(str; doctype = "md2tex")
doc.format.formatdict[:keep_unicode] = true
doc.format.keep_unicode = true
doc = Weave.format(doc)
@test occursin("α", doc)
@test !occursin(Weave.uc2tex("α"), doc)