From 82c7c2a8c61601eb6ddcf2fbbb294f368b3cbfc5 Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Sun, 14 Jun 2020 21:33:55 +0900 Subject: [PATCH] rename formats --- src/rendering/htmlformats.jl | 18 ++++++------ src/rendering/miscformats.jl | 4 +-- src/rendering/pandocformats.jl | 4 +-- src/rendering/texformats.jl | 50 +++++++++++++++++----------------- src/writer/latex.jl | 2 +- 5 files changed, 39 insertions(+), 39 deletions(-) diff --git a/src/rendering/htmlformats.jl b/src/rendering/htmlformats.jl index e3cbad2..5cf6eb5 100644 --- a/src/rendering/htmlformats.jl +++ b/src/rendering/htmlformats.jl @@ -12,8 +12,8 @@ render_termchunk(docformat::HTMLFormat, chunk) = # Julia markdown # -------------- -Base.@kwdef mutable struct JMarkdown2HTML <: HTMLFormat - description = "Julia markdown to html" +Base.@kwdef mutable struct WeaveHTML <: HTMLFormat + description = "Weave-style HTML" extension = "html" codestart = "\n" codeend = "\n" @@ -33,9 +33,9 @@ Base.@kwdef mutable struct JMarkdown2HTML <: HTMLFormat stylesheet = nothing highlight_theme = nothing end -register_format!("md2html", JMarkdown2HTML()) +register_format!("md2html", WeaveHTML()) -function set_format_options!(docformat::JMarkdown2HTML; template = nothing, css = nothing, highlight_theme = nothing, _kwargs...) +function set_format_options!(docformat::WeaveHTML; template = nothing, css = nothing, highlight_theme = nothing, _kwargs...) template_path = isnothing(template) ? normpath(TEMPLATE_DIR, "md2html.tpl") : template docformat.template = get_mustache_template(template_path) stylesheet_path = isnothing(css) ? normpath(STYLESHEET_DIR, "skeleton.css") : css @@ -44,7 +44,7 @@ function set_format_options!(docformat::JMarkdown2HTML; template = nothing, css end # very similar to tex version of function -function render_chunk(docformat::JMarkdown2HTML, chunk::DocChunk) +function render_chunk(docformat::WeaveHTML, chunk::DocChunk) out = IOBuffer() io = IOBuffer() for inline in chunk.content @@ -63,9 +63,9 @@ function render_chunk(docformat::JMarkdown2HTML, chunk::DocChunk) return take2string!(out) end -render_output(docformat::JMarkdown2HTML, output) = Markdown.htmlesc(output) +render_output(docformat::WeaveHTML, output) = Markdown.htmlesc(output) -function render_figures(docformat::JMarkdown2HTML, chunk) +function render_figures(docformat::WeaveHTML, chunk) fignames = chunk.figures caption = chunk.options[:fig_cap] width = chunk.options[:out_width] @@ -104,7 +104,7 @@ function render_figures(docformat::JMarkdown2HTML, chunk) return result end -function render_doc(docformat::JMarkdown2HTML, body, doc; css = nothing) +function render_doc(docformat::WeaveHTML, body, doc; css = nothing) _, weave_source = splitdir(abspath(doc.source)) weave_version, weave_date = weave_info() @@ -125,7 +125,7 @@ end # ------ Base.@kwdef mutable struct Pandoc2HTML <: HTMLFormat - description = "Markdown to HTML (requires Pandoc 2)" + description = "HTML via intermediate Pandoc Markdown (requires Pandoc 2)" extension = "md" codestart = "\n" codeend = "\n" diff --git a/src/rendering/miscformats.jl b/src/rendering/miscformats.jl index 1800000..09ca0b4 100644 --- a/src/rendering/miscformats.jl +++ b/src/rendering/miscformats.jl @@ -2,7 +2,7 @@ # --------------- Base.@kwdef mutable struct GitHubMarkdown <: WeaveFormat - description = "GitHub markdown" + description = "GitHub Markdown" extension = "md" codestart = "````julia" codeend = "````\n\n" @@ -48,7 +48,7 @@ end # ------------- Base.@kwdef mutable struct Hugo <: WeaveFormat - description = "Hugo markdown (using shortcodes)" + description = "Hugo Markdown (using shortcodes)" extension = "md" codestart = "````julia" codeend = "````\n\n" diff --git a/src/rendering/pandocformats.jl b/src/rendering/pandocformats.jl index a8d0670..cc8ae20 100644 --- a/src/rendering/pandocformats.jl +++ b/src/rendering/pandocformats.jl @@ -34,7 +34,7 @@ function render_figures(docformat::PandocFormat, chunk) end Base.@kwdef mutable struct Pandoc <: PandocFormat - description = "Pandoc markdown" + description = "Pandoc Markdown" extension = "md" codestart = "~~~~{.julia}" codeend = "~~~~~~~~~~~~~\n\n" @@ -55,7 +55,7 @@ register_format!("pandoc", Pandoc()) const DEFAULT_PANDOC_OPTIONS = String[] Base.@kwdef mutable struct Pandoc2PDF <: PandocFormat - description = "Pandoc markdown to PDF" + description = "PDF via intermediate Pandoc Markdown" extension = "md" codestart = "~~~~{.julia}" codeend = "~~~~~~~~~~~~~\n\n" diff --git a/src/rendering/texformats.jl b/src/rendering/texformats.jl index 77463b3..112742c 100644 --- a/src/rendering/texformats.jl +++ b/src/rendering/texformats.jl @@ -1,16 +1,16 @@ # Tex # --- -abstract type TexFormat <: WeaveFormat end +abstract type LaTeXFormat <: WeaveFormat end -function set_format_options!(docformat::TexFormat; keep_unicode = false, template = nothing, _kwargs...) +function set_format_options!(docformat::LaTeXFormat; keep_unicode = false, template = nothing, _kwargs...) docformat.keep_unicode |= keep_unicode docformat.template = get_mustache_template(isnothing(template) ? normpath(TEMPLATE_DIR, "md2pdf.tpl") : template) end # very similar to export to html -function render_chunk(docformat::TexFormat, chunk::DocChunk) +function render_chunk(docformat::LaTeXFormat, chunk::DocChunk) out = IOBuffer() io = IOBuffer() for inline in chunk.content @@ -30,11 +30,11 @@ function render_chunk(docformat::TexFormat, chunk::DocChunk) return unicode2latex(docformat, out) end -render_output(docformat::TexFormat, output) = unicode2latex(docformat, output, true) +render_output(docformat::LaTeXFormat, output) = unicode2latex(docformat, output, true) -render_code(docformat::TexFormat, code) = unicode2latex(docformat, code, true) +render_code(docformat::LaTeXFormat, code) = unicode2latex(docformat, code, true) -render_termchunk(docformat::TexFormat, chunk) = string(docformat.termstart, chunk.output, docformat.termend, "\n") +render_termchunk(docformat::LaTeXFormat, chunk) = string(docformat.termstart, chunk.output, docformat.termend, "\n") # from julia symbols (e.g. "\bfhoge") to valid latex const UNICODE2LATEX = let @@ -54,7 +54,7 @@ const UNICODE2LATEX = let Dict(unicode => texify(sym) for (sym, unicode) in REPL.REPLCompletions.latex_symbols) end -function unicode2latex(docformat::TexFormat, s, escape = false) +function unicode2latex(docformat::LaTeXFormat, s, escape = false) # Check whether to convert at all and return input if not docformat.keep_unicode && return s for (unicode, latex) in UNICODE2LATEX @@ -65,7 +65,7 @@ function unicode2latex(docformat::TexFormat, s, escape = false) return s end -function render_figures(docformat::TexFormat, chunk) +function render_figures(docformat::LaTeXFormat, chunk) fignames = chunk.figures caption = chunk.options[:fig_cap] width = chunk.options[:out_width] @@ -133,7 +133,7 @@ function md_length_to_latex(def, reference) return def end -function render_doc(docformat::TexFormat, body, doc) +function render_doc(docformat::LaTeXFormat, body, doc) return Mustache.render( docformat.template; body = body, @@ -146,8 +146,8 @@ end # minted Tex # ---------- -Base.@kwdef mutable struct TexMinted <: TexFormat - description = "Latex using minted for highlighting" +Base.@kwdef mutable struct LaTeXMinted <: LaTeXFormat + description = "LaTeX using minted package for code highlighting" extension = "tex" codestart = "\\begin{minted}[escapeinside=||, mathescape, fontsize=\\small, xleftmargin=0.5em]{julia}" codeend = "\\end{minted}" @@ -169,21 +169,21 @@ Base.@kwdef mutable struct TexMinted <: TexFormat escape_starter = "|\$" escape_closer = reverse(escape_starter) end -register_format!("texminted", TexMinted()) +register_format!("texminted", LaTeXMinted()) # Tex (directly to PDF) # --------------------- -abstract type JMarkdownTexFormat <: TexFormat end +abstract type WeaveLaTeXFormat <: LaTeXFormat end -function set_format_options!(docformat::JMarkdownTexFormat; template = nothing, highlight_theme = nothing, keep_unicode = false, _kwargs...) +function set_format_options!(docformat::WeaveLaTeXFormat; template = nothing, highlight_theme = nothing, keep_unicode = false, _kwargs...) docformat.template = get_mustache_template(isnothing(template) ? normpath(TEMPLATE_DIR, "md2pdf.tpl") : template) docformat.highlight_theme = get_highlight_theme(highlight_theme) docformat.keep_unicode |= keep_unicode end -function render_output(docformat::JMarkdownTexFormat, output) +function render_output(docformat::WeaveLaTeXFormat, output) # Highligts has some extra escaping defined, eg of $, ", ... output_escaped = sprint( (io, x) -> @@ -193,15 +193,15 @@ function render_output(docformat::JMarkdownTexFormat, output) return unicode2latex(docformat, output_escaped, true) end -function render_code(docformat::JMarkdownTexFormat, code) +function render_code(docformat::WeaveLaTeXFormat, code) ret = highlight_code(MIME("text/latex"), code, docformat.highlight_theme) unicode2latex(docformat, ret, false) end -render_termchunk(docformat::JMarkdownTexFormat, chunk) = +render_termchunk(docformat::WeaveLaTeXFormat, chunk) = should_render(chunk) ? highlight_term(MIME("text/latex"), chunk.output, docformat.highlight_theme) : "" -function render_doc(docformat::JMarkdownTexFormat, body, doc) +function render_doc(docformat::WeaveLaTeXFormat, body, doc) return Mustache.render( docformat.template; body = body, @@ -211,8 +211,8 @@ function render_doc(docformat::JMarkdownTexFormat, body, doc) ) end -Base.@kwdef mutable struct JMarkdown2Tex <: JMarkdownTexFormat - description = "Julia markdown to LaTeX" +Base.@kwdef mutable struct WeaveLaTeX <: WeaveLaTeXFormat + description = "Weave-styled LaTeX" extension = "tex" codestart = "" codeend = "" @@ -235,13 +235,13 @@ Base.@kwdef mutable struct JMarkdown2Tex <: JMarkdownTexFormat escape_starter = "(*@" escape_closer = reverse(escape_starter) end -register_format!("md2tex", JMarkdown2Tex()) +register_format!("md2tex", WeaveLaTeX()) # will be used by `write_doc` const DEFAULT_LATEX_CMD = ["xelatex", "-shell-escape", "-halt-on-error"] -Base.@kwdef mutable struct JMarkdown2PDF <: JMarkdownTexFormat - description = "Julia markdown to LaTeX" +Base.@kwdef mutable struct WeaveLaTeX2PDF <: WeaveLaTeXFormat + description = "PDF via Weave-styled LaTeX" extension = "tex" codestart = "" codeend = "" @@ -265,9 +265,9 @@ Base.@kwdef mutable struct JMarkdown2PDF <: JMarkdownTexFormat escape_starter = "(*@" escape_closer = reverse(escape_starter) end -register_format!("md2pdf", JMarkdown2PDF()) +register_format!("md2pdf", WeaveLaTeX2PDF()) -function set_format_options!(docformat::JMarkdown2PDF; template = nothing, highlight_theme = nothing, keep_unicode = false, latex_cmd = DEFAULT_LATEX_CMD, _kwargs...) +function set_format_options!(docformat::WeaveLaTeX2PDF; template = nothing, highlight_theme = nothing, keep_unicode = false, latex_cmd = DEFAULT_LATEX_CMD, _kwargs...) docformat.template = get_mustache_template(isnothing(template) ? normpath(TEMPLATE_DIR, "md2pdf.tpl") : template) docformat.highlight_theme = get_highlight_theme(highlight_theme) diff --git a/src/writer/latex.jl b/src/writer/latex.jl index 65a2cc8..7bafa94 100644 --- a/src/writer/latex.jl +++ b/src/writer/latex.jl @@ -1,4 +1,4 @@ -function write_doc(docformat::JMarkdown2PDF, doc, rendered, out_path) +function write_doc(docformat::WeaveLaTeX2PDF, doc, rendered, out_path) cd_back = let d = pwd(); () -> cd(d); end cd(doc.cwd) try