2020-05-16 18:16:59 +02:00
|
|
|
using Mustache, Highlights, .WeaveMarkdown, Markdown, Dates, Pkg
|
2018-07-24 23:40:47 +02:00
|
|
|
using REPL.REPLCompletions: latex_symbols
|
2019-02-28 15:17:03 +01:00
|
|
|
|
2016-12-13 12:26:34 +01:00
|
|
|
function format(doc::WeaveDoc)
|
2020-05-15 17:32:09 +02:00
|
|
|
formatted = String[]
|
2016-12-13 12:26:34 +01:00
|
|
|
docformat = doc.format
|
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
# Complete format dictionaries with defaults
|
2016-12-13 12:26:34 +01:00
|
|
|
formatdict = docformat.formatdict
|
|
|
|
get!(formatdict, :termstart, formatdict[:codestart])
|
|
|
|
get!(formatdict, :termend, formatdict[:codeend])
|
|
|
|
get!(formatdict, :out_width, nothing)
|
|
|
|
get!(formatdict, :out_height, nothing)
|
|
|
|
get!(formatdict, :fig_pos, nothing)
|
|
|
|
get!(formatdict, :fig_env, nothing)
|
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
docformat.formatdict[:cwd] = doc.cwd # pass wd to figure formatters
|
2016-12-15 14:49:21 +01:00
|
|
|
docformat.formatdict[:theme] = doc.highlight_theme
|
2016-12-13 12:26:34 +01:00
|
|
|
|
2020-05-15 16:51:52 +02:00
|
|
|
restore_header!(doc)
|
2016-12-14 20:50:29 +01:00
|
|
|
|
2016-12-13 12:26:34 +01:00
|
|
|
for chunk in copy(doc.chunks)
|
2019-10-15 21:48:05 +02:00
|
|
|
result = format_chunk(chunk, formatdict, docformat)
|
2016-12-13 12:26:34 +01:00
|
|
|
push!(formatted, result)
|
|
|
|
end
|
|
|
|
|
|
|
|
formatted = join(formatted, "\n")
|
|
|
|
# Render using a template if needed
|
2020-05-15 17:32:09 +02:00
|
|
|
return render_doc(formatted, doc)
|
2016-12-13 12:26:34 +01:00
|
|
|
end
|
|
|
|
|
2020-05-15 17:32:09 +02:00
|
|
|
render_doc(formatted, doc) = render_doc(formatted, doc, doc.format)
|
2016-12-13 12:26:34 +01:00
|
|
|
|
2020-05-15 17:32:09 +02:00
|
|
|
render_doc(formatted, doc, format) = formatted
|
2016-12-13 12:26:34 +01:00
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
function highlight(
|
|
|
|
mime::MIME,
|
2020-05-16 10:59:17 +02:00
|
|
|
output,
|
2020-05-08 16:39:17 +02:00
|
|
|
lexer,
|
|
|
|
theme = Highlights.Themes.DefaultTheme,
|
|
|
|
)
|
2020-05-16 10:59:17 +02:00
|
|
|
return sprint((io, x) -> Highlights.highlight(io, mime, x, lexer, theme), output)
|
2018-07-25 00:33:24 +02:00
|
|
|
end
|
|
|
|
|
2016-12-15 14:49:21 +01:00
|
|
|
function stylesheet(m::MIME, theme)
|
2020-05-08 16:39:17 +02:00
|
|
|
return sprint((io, x) -> Highlights.stylesheet(io, m, x), theme)
|
2016-12-14 15:07:04 +01:00
|
|
|
end
|
2016-12-13 12:26:34 +01:00
|
|
|
|
2020-05-15 17:32:09 +02:00
|
|
|
function render_doc(formatted, doc, format::JMarkdown2HTML)
|
2020-05-08 16:39:17 +02:00
|
|
|
css = stylesheet(MIME("text/html"), doc.highlight_theme)
|
|
|
|
path, wsource = splitdir(abspath(doc.source))
|
2020-05-16 18:16:59 +02:00
|
|
|
wversion, wdate = weave_info()
|
2020-05-08 16:39:17 +02:00
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
theme_path = isempty(doc.css) ? normpath(TEMPLATE_DIR, "skeleton_css.css") : doc.css
|
|
|
|
theme_css = read(theme_path, String)
|
2016-12-15 14:49:21 +01:00
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
template = if isa(doc.template, Mustache.MustacheTokens)
|
|
|
|
doc.template
|
2020-05-08 16:39:17 +02:00
|
|
|
else
|
2020-05-16 10:59:17 +02:00
|
|
|
template_path = isempty(doc.template) ? normpath(TEMPLATE_DIR, "julia_html.tpl") : doc.template
|
|
|
|
Mustache.template_from_file(template_path)
|
2020-05-08 16:39:17 +02:00
|
|
|
end
|
2018-07-24 23:40:47 +02:00
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
return Mustache.render(
|
|
|
|
template;
|
|
|
|
themecss = theme_css,
|
|
|
|
highlightcss = css,
|
|
|
|
body = formatted,
|
|
|
|
header_script = doc.header_script,
|
|
|
|
source = wsource,
|
|
|
|
wversion = wversion,
|
2020-05-16 18:16:59 +02:00
|
|
|
wdate = wdate,
|
2020-05-08 16:39:17 +02:00
|
|
|
[Pair(Symbol(k), v) for (k, v) in doc.header]...,
|
|
|
|
)
|
|
|
|
end
|
2019-03-10 16:51:19 +01:00
|
|
|
|
2020-05-15 17:32:09 +02:00
|
|
|
function render_doc(formatted, doc, format::JMarkdown2tex)
|
2020-05-08 16:39:17 +02:00
|
|
|
highlight = stylesheet(MIME("text/latex"), doc.highlight_theme)
|
|
|
|
path, wsource = splitdir(abspath(doc.source))
|
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
template = if isa(doc.template, Mustache.MustacheTokens)
|
|
|
|
doc.template
|
2020-05-08 16:39:17 +02:00
|
|
|
else
|
2020-05-16 10:59:17 +02:00
|
|
|
template_path = isempty(doc.template) ? normpath(TEMPLATE_DIR, "julia_tex.tpl") : doc.template
|
|
|
|
Mustache.template_from_file(template_path)
|
2020-05-08 16:39:17 +02:00
|
|
|
end
|
2016-12-14 15:07:04 +01:00
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
return Mustache.render(
|
|
|
|
template;
|
|
|
|
body = formatted,
|
|
|
|
highlight = highlight,
|
|
|
|
[Pair(Symbol(k), v) for (k, v) in doc.header]...,
|
|
|
|
)
|
2016-12-13 12:26:34 +01:00
|
|
|
end
|
|
|
|
|
2020-05-16 18:16:59 +02:00
|
|
|
const WEAVE_VERSION = try
|
|
|
|
'v' * Pkg.TOML.parsefile(normpath(PKG_DIR, "Project.toml"))["version"]
|
|
|
|
catch
|
|
|
|
""
|
|
|
|
end
|
|
|
|
|
|
|
|
weave_info() = WEAVE_VERSION, string(Date(now()))
|
|
|
|
|
2020-05-16 16:31:27 +02:00
|
|
|
# TODO: is there any other format where we want to restore headers ?
|
|
|
|
const HEADER_PRESERVE_DOCTYPES = ("github", "hugo")
|
|
|
|
|
2020-05-15 16:51:52 +02:00
|
|
|
function restore_header!(doc)
|
2020-05-16 16:31:27 +02:00
|
|
|
doc.doctype in HEADER_PRESERVE_DOCTYPES || return # don't restore
|
2020-05-15 16:51:52 +02:00
|
|
|
|
|
|
|
# only strips Weave headers
|
|
|
|
delete!(doc.header, WEAVE_OPTION_NAME)
|
|
|
|
isempty(doc.header) && return
|
|
|
|
|
|
|
|
# restore remained headers as `DocChunk`
|
|
|
|
header_text = "---\n$(YAML.write(doc.header))---"
|
|
|
|
pushfirst!(doc.chunks, DocChunk(header_text, 0, 0))
|
2016-12-14 20:50:29 +01:00
|
|
|
end
|
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
format_chunk(chunk::DocChunk, formatdict, docformat) = join((format_inline(c) for c in chunk.content))
|
2016-12-26 23:59:15 +01:00
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
format_inline(inline::InlineText) = inline.content
|
2016-12-26 23:59:15 +01:00
|
|
|
|
|
|
|
function format_inline(inline::InlineCode)
|
|
|
|
isempty(inline.rich_output) || return inline.rich_output
|
|
|
|
isempty(inline.figures) || return inline.figures[end]
|
2020-05-16 10:59:17 +02:00
|
|
|
return inline.output
|
2016-12-13 12:26:34 +01:00
|
|
|
end
|
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
function ioformat!(io::IOBuffer, out::IOBuffer, fun = WeaveMarkdown.latex)
|
2019-03-06 21:27:47 +01:00
|
|
|
text = String(take!(io))
|
|
|
|
if !isempty(text)
|
2020-05-08 16:39:17 +02:00
|
|
|
m = Markdown.parse(text, flavor = WeaveMarkdown.weavemd)
|
2019-03-06 21:27:47 +01:00
|
|
|
write(out, string(fun(m)))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
addspace(op, inline) = (inline.ctype === :line && (op = "\n$op\n"); op)
|
2016-12-13 12:26:34 +01:00
|
|
|
|
2019-10-15 21:48:05 +02:00
|
|
|
function format_chunk(chunk::DocChunk, formatdict, docformat::JMarkdown2tex)
|
2019-03-06 21:27:47 +01:00
|
|
|
out = IOBuffer()
|
|
|
|
io = IOBuffer()
|
|
|
|
for inline in chunk.content
|
|
|
|
if isa(inline, InlineText)
|
|
|
|
write(io, inline.content)
|
|
|
|
elseif !isempty(inline.rich_output)
|
|
|
|
ioformat!(io, out)
|
|
|
|
write(out, addspace(inline.rich_output, inline))
|
|
|
|
elseif !isempty(inline.figures)
|
2019-03-10 18:23:18 +01:00
|
|
|
write(io, inline.figures[end], inline)
|
2019-03-06 21:27:47 +01:00
|
|
|
elseif !isempty(inline.output)
|
|
|
|
write(io, addspace(inline.output, inline))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
ioformat!(io, out)
|
2019-10-15 21:48:05 +02:00
|
|
|
formatdict[:keep_unicode] || return uc2tex(String(take!(out)))
|
2019-09-05 10:13:49 +02:00
|
|
|
return String(take!(out))
|
2019-03-06 21:27:47 +01:00
|
|
|
end
|
|
|
|
|
2019-10-15 21:48:05 +02:00
|
|
|
function format_chunk(chunk::DocChunk, formatdict, docformat::JMarkdown2HTML)
|
2019-03-06 21:27:47 +01:00
|
|
|
out = IOBuffer()
|
|
|
|
io = IOBuffer()
|
|
|
|
fun = WeaveMarkdown.html
|
|
|
|
for inline in chunk.content
|
|
|
|
if isa(inline, InlineText)
|
|
|
|
write(io, inline.content)
|
|
|
|
elseif !isempty(inline.rich_output)
|
|
|
|
ioformat!(io, out, fun)
|
|
|
|
write(out, addspace(inline.rich_output, inline))
|
|
|
|
elseif !isempty(inline.figures)
|
2019-03-10 19:10:30 +01:00
|
|
|
write(io, inline.figures[end])
|
2019-03-06 21:27:47 +01:00
|
|
|
elseif !isempty(inline.output)
|
|
|
|
write(io, addspace(inline.output, inline))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
ioformat!(io, out, fun)
|
|
|
|
return String(take!(out))
|
2016-12-14 15:07:04 +01:00
|
|
|
end
|
2016-12-13 12:26:34 +01:00
|
|
|
|
2019-10-15 21:48:05 +02:00
|
|
|
function format_chunk(chunk::CodeChunk, formatdict, docformat)
|
2020-05-08 16:39:17 +02:00
|
|
|
# Fill undefined options with format specific defaults
|
2016-12-13 12:26:34 +01:00
|
|
|
chunk.options[:out_width] == nothing &&
|
2020-05-08 16:39:17 +02:00
|
|
|
(chunk.options[:out_width] = formatdict[:out_width])
|
|
|
|
chunk.options[:fig_pos] == nothing && (chunk.options[:fig_pos] = formatdict[:fig_pos])
|
2016-12-13 12:26:34 +01:00
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
# Only use floats if chunk has caption or sets fig_env
|
2016-12-13 12:26:34 +01:00
|
|
|
if chunk.options[:fig_cap] != nothing && chunk.options[:fig_env] == nothing
|
2020-05-08 16:39:17 +02:00
|
|
|
(chunk.options[:fig_env] = formatdict[:fig_env])
|
2016-12-13 12:26:34 +01:00
|
|
|
end
|
|
|
|
|
|
|
|
if haskey(formatdict, :indent)
|
|
|
|
chunk.content = indent(chunk.content, formatdict[:indent])
|
|
|
|
end
|
|
|
|
|
2019-10-15 21:48:05 +02:00
|
|
|
chunk.content = format_code(chunk.content, docformat)
|
2016-12-13 14:30:23 +01:00
|
|
|
|
2016-12-13 12:26:34 +01:00
|
|
|
if !chunk.options[:eval]
|
|
|
|
if chunk.options[:echo]
|
2017-03-13 14:05:07 +01:00
|
|
|
result = "$(formatdict[:codestart])\n$(chunk.content)$(formatdict[:codeend])"
|
2016-12-13 12:26:34 +01:00
|
|
|
return result
|
|
|
|
else
|
|
|
|
r = ""
|
|
|
|
return r
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
if chunk.options[:term]
|
2016-12-13 13:20:40 +01:00
|
|
|
result = format_termchunk(chunk, formatdict, docformat)
|
2016-12-13 12:26:34 +01:00
|
|
|
else
|
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
if chunk.options[:echo]
|
|
|
|
# Convert to output format and highlight (html, tex...) if needed
|
|
|
|
result = "$(formatdict[:codestart])$(chunk.content)$(formatdict[:codeend])\n"
|
2016-12-13 12:26:34 +01:00
|
|
|
else
|
2020-05-08 16:39:17 +02:00
|
|
|
result = ""
|
|
|
|
end
|
2018-01-03 16:23:57 +01:00
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
if (strip(chunk.output) != "" || strip(chunk.rich_output) != "") &&
|
|
|
|
(chunk.options[:results] != "hidden")
|
|
|
|
if chunk.options[:results] != "markup" && chunk.options[:results] != "hold"
|
|
|
|
strip(chunk.output) ≠ "" && (result *= "$(chunk.output)\n")
|
|
|
|
strip(chunk.rich_output) ≠ "" && (result *= "$(chunk.rich_output)\n")
|
|
|
|
else
|
|
|
|
if chunk.options[:wrap]
|
|
|
|
chunk.output =
|
|
|
|
"\n" * wraplines(chunk.output, chunk.options[:line_width])
|
|
|
|
chunk.output = format_output(chunk.output, docformat)
|
|
|
|
else
|
|
|
|
chunk.output = "\n" * rstrip(chunk.output)
|
|
|
|
chunk.output = format_output(chunk.output, docformat)
|
|
|
|
end
|
|
|
|
|
|
|
|
if haskey(formatdict, :indent)
|
|
|
|
chunk.output = indent(chunk.output, formatdict[:indent])
|
|
|
|
end
|
|
|
|
strip(chunk.output) ≠ "" && (
|
|
|
|
result *= "$(formatdict[:outputstart])$(chunk.output)\n$(formatdict[:outputend])\n"
|
|
|
|
)
|
|
|
|
strip(chunk.rich_output) ≠ "" && (result *= chunk.rich_output * "\n")
|
2016-12-13 12:26:34 +01:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
# Handle figures
|
2016-12-13 12:26:34 +01:00
|
|
|
if chunk.options[:fig] && length(chunk.figures) > 0
|
|
|
|
if chunk.options[:include]
|
|
|
|
result *= formatfigures(chunk, docformat)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
format_output(result, docformat) = result
|
2016-12-13 12:26:34 +01:00
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
format_output(result, docformat::JMarkdown2HTML) = Markdown.htmlesc(result)
|
2018-07-24 23:40:47 +02:00
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
function format_output(result, docformat::JMarkdown2tex)
|
2020-05-08 16:39:17 +02:00
|
|
|
# Highligts has some extra escaping defined, eg of $, ", ...
|
|
|
|
result_escaped = sprint(
|
|
|
|
(io, x) ->
|
|
|
|
Highlights.Format.escape(io, MIME("text/latex"), x, charescape = true),
|
|
|
|
result,
|
|
|
|
)
|
|
|
|
docformat.formatdict[:keep_unicode] || return uc2tex(result_escaped, true)
|
|
|
|
return result_escaped
|
2016-12-13 12:26:34 +01:00
|
|
|
end
|
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
format_code(result, docformat) = result
|
2016-12-13 12:26:34 +01:00
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
function format_code(result, docformat::JMarkdown2tex)
|
2020-05-08 16:39:17 +02:00
|
|
|
highlighted = highlight(
|
|
|
|
MIME("text/latex"),
|
|
|
|
strip(result),
|
|
|
|
Highlights.Lexers.JuliaLexer,
|
|
|
|
docformat.formatdict[:theme],
|
|
|
|
)
|
|
|
|
docformat.formatdict[:keep_unicode] || return uc2tex(highlighted)
|
|
|
|
return highlighted
|
|
|
|
# return "\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}\n$result\n\\end{minted}\n"
|
2018-07-24 23:40:47 +02:00
|
|
|
end
|
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
# Convert unicode to tex, escape listings if needed
|
|
|
|
function uc2tex(s, escape = false)
|
2018-07-24 23:40:47 +02:00
|
|
|
for key in keys(latex_symbols)
|
|
|
|
if escape
|
2019-02-26 16:38:28 +01:00
|
|
|
s = replace(s, latex_symbols[key] => "(*@\\ensuremath{$(texify(key))}@*)")
|
2018-07-24 23:40:47 +02:00
|
|
|
else
|
2019-02-26 16:38:28 +01:00
|
|
|
s = replace(s, latex_symbols[key] => "\\ensuremath{$(texify(key))}")
|
2018-07-24 23:40:47 +02:00
|
|
|
end
|
|
|
|
end
|
|
|
|
return s
|
2016-12-14 15:07:04 +01:00
|
|
|
end
|
|
|
|
|
2019-02-26 16:38:28 +01:00
|
|
|
# Make julia symbols (\bf* etc.) valid latex
|
|
|
|
function texify(s)
|
|
|
|
ts = ""
|
|
|
|
if occursin(r"^\\bf[A-Z]$", s)
|
|
|
|
ts = replace(s, "\\bf" => "\\bm{\\mathrm{") * "}}"
|
|
|
|
elseif startswith(s, "\\bfrak")
|
|
|
|
ts = replace(s, "\\bfrak" => "\\bm{\\mathfrak{") * "}}"
|
|
|
|
elseif startswith(s, "\\bf")
|
|
|
|
ts = replace(s, "\\bf" => "\\bm{\\") * "}"
|
|
|
|
elseif startswith(s, "\\frak")
|
|
|
|
ts = replace(s, "\\frak" => "\\mathfrak{") * "}"
|
|
|
|
else
|
|
|
|
ts = s
|
|
|
|
end
|
|
|
|
return ts
|
|
|
|
end
|
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
function format_code(result, docformat::JMarkdown2HTML)
|
2020-05-08 16:39:17 +02:00
|
|
|
return highlight(
|
|
|
|
MIME("text/html"),
|
|
|
|
strip(result),
|
|
|
|
Highlights.Lexers.JuliaLexer,
|
|
|
|
docformat.formatdict[:theme],
|
|
|
|
)
|
2016-12-13 12:26:34 +01:00
|
|
|
end
|
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
function format_code(result, docformat::Pandoc2HTML)
|
2020-05-08 16:39:17 +02:00
|
|
|
return highlight(
|
|
|
|
MIME("text/html"),
|
|
|
|
strip(result),
|
|
|
|
Highlights.Lexers.JuliaLexer,
|
|
|
|
docformat.formatdict[:theme],
|
|
|
|
)
|
2018-07-25 00:33:24 +02:00
|
|
|
end
|
2018-01-04 17:00:01 +01:00
|
|
|
|
2016-12-13 13:20:40 +01:00
|
|
|
function format_termchunk(chunk, formatdict, docformat)
|
2016-12-13 12:26:34 +01:00
|
|
|
if chunk.options[:echo] && chunk.options[:results] != "hidden"
|
|
|
|
result = "$(formatdict[:termstart])$(chunk.output)\n" * "$(formatdict[:termend])\n"
|
2016-12-13 13:20:40 +01:00
|
|
|
else
|
|
|
|
result = ""
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
|
|
|
function format_termchunk(chunk, formatdict, docformat::JMarkdown2HTML)
|
|
|
|
if chunk.options[:echo] && chunk.options[:results] != "hidden"
|
2020-05-08 16:39:17 +02:00
|
|
|
result = highlight(
|
|
|
|
MIME("text/html"),
|
|
|
|
strip(chunk.output),
|
|
|
|
Highlights.Lexers.JuliaConsoleLexer,
|
|
|
|
docformat.formatdict[:theme],
|
|
|
|
)
|
2016-12-13 12:26:34 +01:00
|
|
|
else
|
|
|
|
result = ""
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2018-01-04 17:00:01 +01:00
|
|
|
function format_termchunk(chunk, formatdict, docformat::Pandoc2HTML)
|
|
|
|
if chunk.options[:echo] && chunk.options[:results] != "hidden"
|
2020-05-08 16:39:17 +02:00
|
|
|
result = highlight(
|
|
|
|
MIME("text/html"),
|
|
|
|
strip(chunk.output),
|
|
|
|
Highlights.Lexers.JuliaConsoleLexer,
|
|
|
|
docformat.formatdict[:theme],
|
|
|
|
)
|
2018-01-04 17:00:01 +01:00
|
|
|
else
|
|
|
|
result = ""
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2016-12-16 19:18:37 +01:00
|
|
|
function format_termchunk(chunk, formatdict, docformat::JMarkdown2tex)
|
|
|
|
if chunk.options[:echo] && chunk.options[:results] != "hidden"
|
2020-05-08 16:39:17 +02:00
|
|
|
result = highlight(
|
|
|
|
MIME("text/latex"),
|
|
|
|
strip(chunk.output),
|
|
|
|
Highlights.Lexers.JuliaConsoleLexer,
|
|
|
|
docformat.formatdict[:theme],
|
|
|
|
)
|
|
|
|
# return "\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}\n$result\n\\end{minted}\n"
|
2016-12-16 19:18:37 +01:00
|
|
|
else
|
|
|
|
result = ""
|
|
|
|
end
|
|
|
|
return result
|
|
|
|
end
|
|
|
|
|
2020-05-16 10:59:17 +02:00
|
|
|
indent(text, nindent) = join(map(x -> string(repeat(' ', nindent), x), split(text, '\n')), '\n')
|
2016-12-13 12:26:34 +01:00
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
function wraplines(text, line_width = 75)
|
2016-12-13 12:26:34 +01:00
|
|
|
result = AbstractString[]
|
|
|
|
lines = split(text, "\n")
|
|
|
|
for line in lines
|
|
|
|
if length(line) > line_width
|
|
|
|
push!(result, wrapline(line, line_width))
|
|
|
|
else
|
|
|
|
push!(result, line)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
return strip(join(result, "\n"))
|
|
|
|
end
|
|
|
|
|
2020-05-08 16:39:17 +02:00
|
|
|
function wrapline(text, line_width = 75)
|
2019-02-25 23:09:40 +01:00
|
|
|
result = ""
|
2016-12-13 12:26:34 +01:00
|
|
|
while length(text) > line_width
|
2020-05-08 16:39:17 +02:00
|
|
|
result *= first(text, line_width) * "\n"
|
|
|
|
text = chop(text, head = line_width, tail = 0)
|
2016-12-13 12:26:34 +01:00
|
|
|
end
|
2019-02-25 23:09:40 +01:00
|
|
|
result *= text
|
2016-12-13 12:26:34 +01:00
|
|
|
end
|