diff --git a/src/rendering/exportformat.jl b/src/rendering/exportformat.jl new file mode 100644 index 0000000..769a1ab --- /dev/null +++ b/src/rendering/exportformat.jl @@ -0,0 +1,24 @@ +abstract type ExportFormat <: WeaveFormat end + +function Base.getproperty(sf::ExportFormat, s::Symbol) + hasfield(typeof(sf), s) && return getfield(sf, s) + return getproperty(sf.primaryformat, s) +end +function Base.setproperty!(sf::ExportFormat, s::Symbol, v) + if hasfield(typeof(sf), s) + setfield!(sf, s, v) + else + setproperty!(sf.primaryformat, s, v) + end +end +function Base.hasproperty(sf::ExportFormat, s::Symbol) + hasfield(typeof(sf), s) || hasfield(typeof(sf.primaryformat), s) +end + +render_doc(df::ExportFormat, body, doc) = render_doc(df.primaryformat, body, doc) + +render_chunk(df::ExportFormat, chunk) = render_chunk(df.primaryformat, chunk) +# Need to define these to avoid ambiguities +render_chunk(df::ExportFormat, chunk::DocChunk) = render_chunk(df.primaryformat, chunk) +render_chunk(df::ExportFormat, chunk::CodeChunk) = render_chunk(df.primaryformat, chunk) +render_output(df::ExportFormat, output) = render_output(df.primaryformat, output) diff --git a/src/rendering/rendering.jl b/src/rendering/rendering.jl index 5bbc4b4..63776c6 100644 --- a/src/rendering/rendering.jl +++ b/src/rendering/rendering.jl @@ -23,9 +23,9 @@ function render_doc(doc::WeaveDoc) return render_doc(docformat, body, doc) end - +include("exportformat.jl") include("common.jl") +include("pandocformats.jl") include("htmlformats.jl") include("texformats.jl") -include("pandocformats.jl") include("miscformats.jl") diff --git a/src/rendering/texformats.jl b/src/rendering/texformats.jl index 24f8676..825d7eb 100644 --- a/src/rendering/texformats.jl +++ b/src/rendering/texformats.jl @@ -250,7 +250,7 @@ register_format!("md2tex", WeaveLaTeX()) const DEFAULT_LATEX_CMD = ["xelatex", "-shell-escape", "-halt-on-error"] -Base.@kwdef mutable struct LaTeX2PDF <: LaTeXFormat +Base.@kwdef mutable struct LaTeX2PDF <: ExportFormat primaryformat = WeaveLaTeX() description = "PDF via LaTeX" latex_cmd = DEFAULT_LATEX_CMD @@ -258,29 +258,7 @@ end register_format!("md2pdf", LaTeX2PDF()) register_format!("minted2pdf", LaTeX2PDF(primaryformat=LaTeXMinted())) -function Base.getproperty(sf::LaTeX2PDF, s::Symbol) - hasfield(typeof(sf), s) && return getfield(sf, s) - return getproperty(sf.primaryformat, s) -end -function Base.setproperty!(sf::LaTeX2PDF, s::Symbol, v) - if hasfield(typeof(sf), s) - setfield!(sf, s, v) - else - setproperty!(sf.primaryformat, s, v) - end -end -function Base.hasproperty(sf::LaTeX2PDF, s::Symbol) - hasfield(typeof(sf), s) || hasfield(typeof(sf.primaryformat), s) -end - function set_format_options!(docformat::LaTeX2PDF; latex_cmd = DEFAULT_LATEX_CMD, _kwargs...) docformat.latex_cmd = latex_cmd set_format_options!(docformat.primaryformat; _kwargs...) end - -render_doc(df::LaTeX2PDF, body, doc) = render_doc(df.primaryformat, body, doc) - -render_chunk(df::LaTeX2PDF, chunk) = render_chunk(df.primaryformat, chunk) -# Need to define these to avoid ambiguities -render_chunk(df::LaTeX2PDF, chunk::DocChunk) = render_chunk(df.primaryformat, chunk) -render_chunk(df::LaTeX2PDF, chunk::CodeChunk) = render_chunk(df.primaryformat, chunk)