some cleanup

pull/350/head
Jonas Isensee 2020-05-31 12:07:26 +02:00
parent 3eba5de7f4
commit 45adb8992f
3 changed files with 18 additions and 28 deletions

View File

@ -20,7 +20,8 @@ function format(doc, template = nothing, highlight_theme = nothing; css = nothin
docformat = doc.format
# TODO : put docformat things earlier into docformat struct. that allows us to pass around fewer args
docformat.highlight_theme = get_highlight_theme(highlight_theme)
# this overwrites template given in docformat
docformat.template = template
restore_header!(doc)
lines = map(copy(doc.chunks)) do chunk
@ -28,7 +29,7 @@ function format(doc, template = nothing, highlight_theme = nothing; css = nothin
end
body = join(lines, '\n')
return render_doc(docformat, body, doc, template, css)
return render_doc(docformat, body, doc, css)
end
render_doc(_, body, args...) = body

View File

@ -45,12 +45,12 @@ end
register_format!("pandoc2html", Pandoc2HTML())
function render_doc(docformat::JMarkdown2HTML, body, doc, template, css)
function render_doc(docformat::JMarkdown2HTML, body, doc, css)
_, weave_source = splitdir(abspath(doc.source))
weave_version, weave_date = weave_info()
return Mustache.render(
get_html_template(template);
get_html_template(docformat.template);
body = body,
stylesheet = get_stylesheet(css),
highlight_stylesheet = get_highlight_stylesheet(MIME("text/html"), docformat.highlight_theme),

View File

@ -74,26 +74,15 @@ end
register_format!("texminted", TexMinted())
highlight_str(docformat::TexFormat) = ""
highlight_str(docformat::JMarkdown2tex) =
get_highlight_stylesheet(MIME("text/latex"), docformat.highlight_theme)
isminted(::TexFormat) = false
isminted(::TexMinted) = true
# TODO: template in docformat currently not used
function render_doc(docformat::TexFormat, body, doc, template, _)
function render_doc(docformat::TexFormat, body, doc, _)
return Mustache.render(
get_tex_template(template);
get_tex_template(docformat.template);
body = body,
highlight = "",
tex_deps = docformat.tex_deps,
[Pair(Symbol(k), v) for (k, v) in doc.header]...,
)
end
function render_doc(docformat::JMarkdown2tex, body, doc, template, _)
return Mustache.render(
get_tex_template(template);
body = body,
highlight = get_highlight_stylesheet(MIME("text/latex"), docformat.highlight_theme),
highlight = highlight_str(docformat),
tex_deps = docformat.tex_deps,
[Pair(Symbol(k), v) for (k, v) in doc.header]...,
)
@ -131,14 +120,14 @@ function format_output(result, docformat::TexFormat)
return result_escaped
end
# return "\\begin{minted}[mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}\n$result\n\\end{minted}\n"
# Highlight code is currently only compatible with lstlistings (JMarkdown2tex)
highlight_code(docformat::TexFormat, code) = code
highlight_code(docformat::JMarkdown2tex, code) =
highlight_code(MIME("text/latex"), code, docformat.highlight_theme)
function format_code(code, docformat::TexFormat)
#ret = highlight_code(MIME("text/latex"), code, docformat.highlight_theme)
docformat.keep_unicode || return uc2tex(code)
return code
end
function format_code(code, docformat::JMarkdown2tex)
ret = highlight_code(MIME("text/latex"), code, docformat.highlight_theme)
ret = highlight_code(code, docformat)
docformat.keep_unicode || return uc2tex(ret)
return ret
end