pass fewer arguments and bugfixes

pull/350/head
Jonas Isensee 2020-05-31 13:26:27 +02:00
parent 45adb8992f
commit 9875bc10f7
6 changed files with 29 additions and 12 deletions

View File

@ -129,6 +129,7 @@ function weave(
)
doc = WeaveDoc(source, informat)
# TODO : put all argument parsing into separate function
# run document
# ------------
@ -198,7 +199,10 @@ function weave(
end
doc.format.keep_unicode = doc.format.keep_unicode | keep_unicode
rendered = format(doc, template, highlight_theme; css = css)
doc.format.highlight_theme = get_highlight_theme(highlight_theme)
# this overwrites template given in docformat
doc.format.template = template
rendered = format(doc; css = css)
outname = get_outname(out_path, doc)

View File

@ -10,18 +10,12 @@ const FORMATS = Dict{String,WeaveFormat}()
register_format!(format_name::AbstractString, format::WeaveFormat) = push!(FORMATS, format_name => format)
register_format!(_,format) = error("Format needs to be a subtype of WeaveFormat.")
# TODO: reorganize this file into multiple files corresponding to each output format
using Mustache, Highlights, .WeaveMarkdown, Markdown, Dates, Pkg
using REPL.REPLCompletions: latex_symbols
function format(doc, template = nothing, highlight_theme = nothing; css = nothing)
function format(doc; css = nothing)
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

View File

@ -20,6 +20,7 @@ Base.@kwdef mutable struct JMarkdown2HTML <: HTMLFormat
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
template = normpath(TEMPLATE_DIR, "md2html.tpl")
end
register_format!("md2html", JMarkdown2HTML())
@ -41,6 +42,7 @@ Base.@kwdef mutable struct Pandoc2HTML <: HTMLFormat
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
template = normpath(TEMPLATE_DIR, "pandoc2html.tpl")
end
register_format!("pandoc2html", Pandoc2HTML())
@ -90,7 +92,7 @@ format_code(code, docformat::HTMLFormat) =
format_termchunk(chunk, docformat::HTMLFormat) =
should_render(chunk) ? highlight_term(MIME("text/html"), chunk.output, docformat.highlight_theme) : ""
formatfigures(chunk, docformat::Pandoc2HTML) = formatfigures(chunk, pandoc)
formatfigures(chunk, docformat::Pandoc2HTML) = formatfigures(chunk, Pandoc())
function formatfigures(chunk, docformat::JMarkdown2HTML)
fignames = chunk.figures

View File

@ -20,6 +20,8 @@ Base.@kwdef mutable struct GitHubMarkdown <: MarkdownFormat
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
#this could be removed
template = nothing
end
register_format!("github", GitHubMarkdown())
@ -33,6 +35,7 @@ Base.@kwdef mutable struct Hugo <: MarkdownFormat
extension = "md"
uglyURLs = false # if `false`, prepend figure path by `..`
keep_unicode = false
mimetypes = default_mime_types
termstart = codestart
termend = codeend
out_width = nothing
@ -40,6 +43,8 @@ Base.@kwdef mutable struct Hugo <: MarkdownFormat
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
#this could be removed
template = nothing
end
register_format!("hugo", Hugo())
@ -59,6 +64,9 @@ Base.@kwdef mutable struct MultiMarkdown <: MarkdownFormat
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
#this could be removed
template = nothing
mimetypes = default_mime_types
end
register_format!("multimarkdown", MultiMarkdown())
@ -85,6 +93,7 @@ Base.@kwdef mutable struct Pandoc <: MarkdownFormat
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
template = nothing
end
register_format!("pandoc", Pandoc())
register_format!("pandoc2pdf", Pandoc())

View File

@ -25,6 +25,7 @@ Base.@kwdef mutable struct JMarkdown2tex <: TexFormat
tex_deps = ""
end
register_format!("md2tex", JMarkdown2tex())
register_format!("md2pdf", JMarkdown2tex())
Base.@kwdef mutable struct Tex <: TexFormat
description = "Latex with custom code environments"
@ -122,8 +123,8 @@ end
# Highlight code is currently only compatible with lstlistings (JMarkdown2tex)
highlight_code(docformat::TexFormat, code) = code
highlight_code(docformat::JMarkdown2tex, code) =
highlight_code(code, docformat::TexFormat) = code
highlight_code(code, docformat::JMarkdown2tex) =
highlight_code(MIME("text/latex"), code, docformat.highlight_theme)
function format_code(code, docformat::TexFormat)

View File

@ -18,6 +18,10 @@ Base.@kwdef mutable struct Rest <: WeaveFormat
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
#this could be removed if argument parsing checked whether the format was
# compatible with templates
template = nothing
mimetypes = default_mime_types
end
register_format!("rst", Rest())
@ -42,6 +46,9 @@ Base.@kwdef mutable struct AsciiDoc <: WeaveFormat
fig_pos = nothing
fig_env = nothing
highlight_theme = nothing
#this could be removed
template = nothing
mimetypes = default_mime_types
end
register_format!("asciidoc", AsciiDoc())