From 29ff436a0010ea29ec69230940a91accb85b6e5f Mon Sep 17 00:00:00 2001 From: Shuhei Kadowaki Date: Sat, 23 May 2020 20:07:59 +0900 Subject: [PATCH] consistent and clearer terminology: - formatted -> body/rendered - wdate -> weave_date - wsource (or source) -> weave_source - wdate -> weave_date --- src/Weave.jl | 8 ++++---- src/format.jl | 32 ++++++++++++++++---------------- src/pandoc.jl | 31 +++++++++++++++---------------- templates/julia_html.tpl | 8 ++++---- templates/pandoc_skeleton.html | 6 +++--- 5 files changed, 42 insertions(+), 43 deletions(-) diff --git a/src/Weave.jl b/src/Weave.jl index 6134730..2b8c7a1 100644 --- a/src/Weave.jl +++ b/src/Weave.jl @@ -192,23 +192,23 @@ function weave( end get!(doc.format.formatdict, :keep_unicode, keep_unicode) - formatted = format(doc, template, highlight_theme; css = css) + rendered = format(doc, template, highlight_theme; css = css) outname = get_outname(out_path, doc) - open(io->write(io,formatted), outname, "w") + open(io->write(io,rendered), outname, "w") # document generation via external programs doctype = doc.doctype if doctype == "pandoc2html" mdname = outname outname = get_outname(out_path, doc, ext = "html") - pandoc2html(formatted, doc, highlight_theme, outname, pandoc_options) + pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options) rm(mdname) elseif doctype == "pandoc2pdf" mdname = outname outname = get_outname(out_path, doc, ext = "pdf") - pandoc2pdf(formatted, doc, outname, pandoc_options) + pandoc2pdf(rendered, doc, outname, pandoc_options) rm(mdname) elseif doctype == "md2pdf" run_latex(doc, outname, latex_cmd) diff --git a/src/format.jl b/src/format.jl index 938bc0d..d39d532 100644 --- a/src/format.jl +++ b/src/format.jl @@ -17,37 +17,37 @@ function format(doc, template = nothing, highlight_theme = nothing; css = nothin restore_header!(doc) - formatted_lines = map(copy(doc.chunks)) do chunk + lines = map(copy(doc.chunks)) do chunk format_chunk(chunk, formatdict, format) end - formatted = join(formatted_lines, '\n') + body = join(lines, '\n') - return format isa JMarkdown2HTML ? render2html(formatted, doc, template, css, highlight_theme) : - format isa JMarkdown2tex ? render2tex(formatted, doc, template, highlight_theme) : - formatted + return format isa JMarkdown2HTML ? render2html(body, doc, template, css, highlight_theme) : + format isa JMarkdown2tex ? render2tex(body, doc, template, highlight_theme) : + body end -function render2html(formatted, doc, template, css, highlight_theme) - _, source = splitdir(abspath(doc.source)) - wversion, wdate = weave_info() +function render2html(body, doc, template, css, highlight_theme) + _, weave_source = splitdir(abspath(doc.source)) + weave_version, weave_date = weave_info() return Mustache.render( get_template(template, false); - body = formatted, - themecss = get_stylesheet(css), - highlightcss = get_highlight_stylesheet(MIME("text/html"), highlight_theme), + body = body, + stylesheet = get_stylesheet(css), + highlight_stylesheet = get_highlight_stylesheet(MIME("text/html"), highlight_theme), header_script = doc.header_script, - source = source, - wversion = wversion, - wdate = wdate, + weave_source = weave_source, + weave_version = weave_version, + weave_date = weave_date, [Pair(Symbol(k), v) for (k, v) in doc.header]..., ) end -function render2tex(formatted, doc, template, highlight_theme) +function render2tex(body, doc, template, highlight_theme) return Mustache.render( get_template(template, true); - body = formatted, + body = body, highlight = get_highlight_stylesheet(MIME("text/latex"), highlight_theme), [Pair(Symbol(k), v) for (k, v) in doc.header]..., ) diff --git a/src/pandoc.jl b/src/pandoc.jl index 194c35e..6f82f5e 100644 --- a/src/pandoc.jl +++ b/src/pandoc.jl @@ -1,10 +1,10 @@ -function pandoc2html(formatted, doc, highlight_theme, outname, pandoc_options) +function pandoc2html(rendered, doc, highlight_theme, outname, pandoc_options) template_path = normpath(PKG_DIR, "templates/pandoc_skeleton.html") - themecss_path = normpath(PKG_DIR, "templates/pandoc_skeleton.css") - highlightcss = get_highlight_stylesheet(MIME("text/html"), highlight_theme) + stylesheet_path = normpath(PKG_DIR, "templates/pandoc_skeleton.css") + highlight_stylesheet = get_highlight_stylesheet(MIME("text/html"), highlight_theme) - path, wsource = splitdir(abspath(doc.source)) - wversion, wdate = weave_info() + _, weave_source = splitdir(abspath(doc.source)) + weave_version, weave_date = weave_info() # Header is inserted from displayed plots header_script = doc.header_script @@ -27,16 +27,16 @@ function pandoc2html(formatted, doc, highlight_theme, outname, pandoc_options) cmd = `pandoc -f markdown+raw_html -s --mathjax="" $filt $citeproc $pandoc_options --template $template_path - -H $themecss_path + -H $stylesheet_path $self_contained - -V wversion=$wversion - -V wdate=$wdate - -V wsource=$wsource - -V highlightcss=$highlightcss - -V headerscript=$header_script - -o $outname` + -V highlight_stylesheet=$highlight_stylesheet + -V weave_version=$weave_version + -V weave_date=$weave_date + -V weave_source=$weave_source + -V headerscript=$header_script + -o $outname` proc = open(cmd, "r+") - println(proc.in, formatted) + println(proc.in, rendered) close(proc.in) proc_output = read(proc.out, String) catch @@ -47,11 +47,10 @@ function pandoc2html(formatted, doc, highlight_theme, outname, pandoc_options) end end -function pandoc2pdf(formatted, doc, outname, pandoc_options) +function pandoc2pdf(rendered, doc, outname, pandoc_options) weavedir = dirname(@__FILE__) header_template = joinpath(weavedir, "../templates/pandoc_header.txt") - path, wsource = splitdir(abspath(doc.source)) outname = basename(outname) # Change path for pandoc @@ -73,7 +72,7 @@ function pandoc2pdf(formatted, doc, outname, pandoc_options) --include-in-header=$header_template -V fontsize=12pt -o $outname` proc = open(cmd, "r+") - println(proc.in, formatted) + println(proc.in, rendered) close(proc.in) proc_output = read(proc.out, String) catch diff --git a/templates/julia_html.tpl b/templates/julia_html.tpl index fdd6820..4f1fdcd 100644 --- a/templates/julia_html.tpl +++ b/templates/julia_html.tpl @@ -16,10 +16,10 @@ - {{{ :highlightcss }}} + {{{ :highlight_stylesheet }}} @@ -38,8 +38,8 @@
diff --git a/templates/pandoc_skeleton.html b/templates/pandoc_skeleton.html index b8f3643..e2e8ad5 100644 --- a/templates/pandoc_skeleton.html +++ b/templates/pandoc_skeleton.html @@ -32,7 +32,7 @@ $for(header-includes)$ $header-includes$ $endfor$ -$highlightcss$ +$highlight_stylesheet$ $if(highlighting-css)$