diff --git a/src/rendering/htmlformats.jl b/src/rendering/htmlformats.jl index 55502b0..a96b5a9 100644 --- a/src/rendering/htmlformats.jl +++ b/src/rendering/htmlformats.jl @@ -1,7 +1,8 @@ # HTML # ---- +abstract type HTMLFormat <: WeaveFormat end -@define_format JMarkdown2HTML +@define_format JMarkdown2HTML <: HTMLFormat register_format!("md2html", JMarkdown2HTML(Dict( :description => "Julia markdown to html", :codestart => "\n", @@ -20,7 +21,7 @@ register_format!("md2html", JMarkdown2HTML(Dict( :extension => "html", ))) -@define_format Pandoc2HTML +@define_format Pandoc2HTML <: HTMLFormat register_format!("pandoc2html", Pandoc2HTML(Dict( :description => "Markdown to HTML (requires Pandoc 2)", :codestart => "\n", @@ -79,20 +80,13 @@ end format_output(result, docformat::JMarkdown2HTML) = Markdown.htmlesc(result) -format_code(code, docformat::JMarkdown2HTML) = +format_code(code, docformat::HTMLFormat) = highlight_code(MIME("text/html"), code, docformat.formatdict[:highlight_theme]) -format_code(code, docformat::Pandoc2HTML) = - highlight_code(MIME("text/html"), code, docformat.formatdict[:highlight_theme]) - - - -format_termchunk(chunk, docformat::JMarkdown2HTML) = - should_render(chunk) ? highlight_term(MIME("text/html"), chunk.output, docformat.formatdict[:highlight_theme]) : "" - -format_termchunk(chunk, docformat::Pandoc2HTML) = +format_termchunk(chunk, docformat::HTMLFormat) = should_render(chunk) ? highlight_term(MIME("text/html"), chunk.output, docformat.formatdict[:highlight_theme]) : "" +formatfigures(chunk, docformat::Pandoc2HTML) = formatfigures(chunk, pandoc) function formatfigures(chunk, docformat::JMarkdown2HTML) fignames = chunk.figures @@ -132,6 +126,3 @@ function formatfigures(chunk, docformat::JMarkdown2HTML) return result end - - -formatfigures(chunk, docformat::Pandoc2HTML) = formatfigures(chunk, pandoc) diff --git a/src/rendering/markdownformats.jl b/src/rendering/markdownformats.jl index fc5c847..8ff8aa7 100644 --- a/src/rendering/markdownformats.jl +++ b/src/rendering/markdownformats.jl @@ -65,8 +65,7 @@ end function formatfigures(chunk, docformat::Hugo) relpath = docformat.formatdict[:uglyURLs] ? "" : ".." - function format_shortcode(index_and_fig) - index, fig = index_and_fig + mapreduce(*, enumerate(chunk.figures), init = "") do (index, fig) if index > 1 @warn("Only the first figure gets a caption.") title_spec = "" @@ -76,7 +75,6 @@ function formatfigures(chunk, docformat::Hugo) end "{{< figure src=\"$(joinpath(relpath, fig))\" $(title_spec) >}}" end - mapreduce(format_shortcode, *, enumerate(chunk.figures), init = "") end function formatfigures(chunk, docformat::MultiMarkdown) diff --git a/src/rendering/texformats.jl b/src/rendering/texformats.jl index 4e72361..7e43996 100644 --- a/src/rendering/texformats.jl +++ b/src/rendering/texformats.jl @@ -89,31 +89,15 @@ register_format!("texminted", TexMinted(Dict( -#### These function are identical -function render_doc(::JMarkdown2tex, body, doc, template, _, highlight_theme) - return Mustache.render( - get_tex_template(template); - body = body, - highlight = get_highlight_stylesheet(MIME("text/latex"), highlight_theme), - [Pair(Symbol(k), v) for (k, v) in doc.header]..., - ) -end +isminted(::TexFormat) = false +isminted(::TexMinted) = true -function render_doc(::Tex, body, doc, template, _, highlight_theme) +function render_doc(docformat::TexFormat, body, doc, template, _, highlight_theme) return Mustache.render( get_tex_template(template); body = body, - highlight = get_highlight_stylesheet(MIME("text/latex"), highlight_theme), - [Pair(Symbol(k), v) for (k, v) in doc.header]..., - ) -end - -function render_doc(::TexMinted, body, doc, template, _, highlight_theme) - return Mustache.render( - get_tex_template(template); - body = body, - highlight = get_highlight_stylesheet(MIME("text/latex"), highlight_theme), - minted = true, + highlight = get_highlight_stylesheet(MIME("text/latex"), highlight_theme, + minted = isminted(docformat)), [Pair(Symbol(k), v) for (k, v) in doc.header]..., ) end