consistent and clearer terminology:

- formatted -> body/rendered
- wdate -> weave_date
- wsource (or source) -> weave_source
- wdate -> weave_date
pull/341/head
Shuhei Kadowaki 2020-05-23 20:07:59 +09:00
parent 3c76b804dc
commit 29ff436a00
5 changed files with 42 additions and 43 deletions

View File

@ -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)

View File

@ -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]...,
)

View File

@ -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

View File

@ -16,10 +16,10 @@
<script type="text/javascript" async src="https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML">
</script>
{{{ :highlightcss }}}
{{{ :highlight_stylesheet }}}
<style type="text/css">
{{{ :themecss }}}
{{{ :stylesheet }}}
</style>
</HEAD>
@ -38,8 +38,8 @@
<HR/>
<div class="footer">
<p>
Published from <a href="{{{:source}}}">{{{:source}}}</a>
using <a href="http://github.com/JunoLab/Weave.jl">Weave.jl</a> {{:wversion}} on {{:wdate}}.
Published from <a href="{{{:weave_source}}}">{{{:weave_source}}}</a>
using <a href="http://github.com/JunoLab/Weave.jl">Weave.jl</a> {{:weave_version}} on {{:weave_date}}.
</p>
</div>
</div>

View File

@ -32,7 +32,7 @@ $for(header-includes)$
$header-includes$
$endfor$
$highlightcss$
$highlight_stylesheet$
$if(highlighting-css)$
<style type="text/css">
@ -85,8 +85,8 @@ $endfor$
<HR/>
<div class="footer"><p>
Published from <a href="$wsource$">$wsource$</a> using
<a href="http://github.com/mpastell/Weave.jl">Weave.jl</a> $wversion$ on $wdate$.
Published from <a href="$source$">$source$</a> using
<a href="http://github.com/mpastell/Weave.jl">Weave.jl</a> $weave_version$ on $weave_date$.
<p></div>
</div>