Make julia Markdown the default when converting to html, Fix term chunks

pull/66/head
Matti Pastell 2016-12-13 14:20:40 +02:00
parent f0bcaf546a
commit d683625444
4 changed files with 70 additions and 16 deletions

View File

@ -70,7 +70,6 @@ function weave(source ; doctype = :auto, plotlib=:auto,
doc = run(doc, doctype = doctype, plotlib=plotlib,
out_path=out_path,
fig_path = fig_path, fig_ext = fig_ext, cache_path = cache_path, cache=cache)
formatted = format(doc)
outname = get_outname(out_path, doc)
@ -80,7 +79,7 @@ function weave(source ; doctype = :auto, plotlib=:auto,
end
#Convert using pandoc
if doc.doctype == "md2html"
if doc.doctype == "pandoc2html"
outname = get_outname(out_path, doc, ext = "html")
pandoc2html(formatted, doc, outname)
elseif doc.doctype == "md2pdf"

View File

@ -45,12 +45,11 @@ function render_doc(formatted, format::JMarkdown2HTML)
theme_css = readstring(joinpath(dirname(@__FILE__), "../templates/skeleton_css.txt"))
template = Mustache.template_from_file(joinpath(dirname(@__FILE__), "../templates/julia_html.txt"))
return Mustache.render(template, theme_css = theme_css,
highlight_css = css, body = formatted)
return Mustache.render(template, themecss = theme_css,
highlightcss = css, body = formatted)
end
function format_chunk(chunk::DocChunk, formatdict, docformat)
#info(typeof(docformat))
return chunk.content
end
@ -88,7 +87,7 @@ function format_chunk(chunk::CodeChunk, formatdict, docformat)
end
if chunk.options[:term]
result = format_termchunk(chunk, formatdict)
result = format_termchunk(chunk, formatdict, docformat)
else
if chunk.options[:echo]
@ -153,11 +152,22 @@ function format_code(result::AbstractString, docformat::JMarkdown2HTML)
return highlighted
end
function format_termchunk(chunk, formatdict)
function format_termchunk(chunk, formatdict, docformat)
if chunk.options[:echo] && chunk.options[:results] != "hidden"
result = "$(formatdict[:termstart])$(chunk.output)\n" * "$(formatdict[:termend])\n"
#chunk.options[:term_state] == :text && (result*= "$(formatdict[:termend])\n")
else
result = ""
end
return result
end
function format_termchunk(chunk, formatdict, docformat::JMarkdown2HTML)
if chunk.options[:echo] && chunk.options[:results] != "hidden"
buf = PipeBuffer()
Highlights.highlight(buf, MIME("text/html"), strip(chunk.output), Highlights.Lexers.JuliaConsoleLexer)
flush(buf)
result = readstring(buf)
close(buf)
else
result = ""
end

View File

@ -57,7 +57,7 @@ const pandoc = Pandoc("Pandoc markdown",
))
const md2html = Pandoc("Markdown to HTML (requires Pandoc)",
const pdoc2html = Pandoc("Markdown to HTML (requires Pandoc)",
Dict{Symbol,Any}(
:codestart => "````julia",
:codeend=> "````\n\n",
@ -105,20 +105,63 @@ type JMarkdown2HTML
formatdict::Dict{Symbol,Any}
end
const jmd2html = JMarkdown2HTML("Julia markdown", Dict{Symbol,Any}(
const md2html = JMarkdown2HTML("Julia markdown", Dict{Symbol,Any}(
:codestart => "\n",
:codeend=> "\n",
:outputstart=> "<pre class=\"hljl\">",
:outputend=> "</pre>\n",
:fig_ext=> ".png",
:extension=> "html",
:doctype=> "html"))
:doctype=> "md2html"))
type MultiMarkdown
description::AbstractString
formatdict::Dict{Symbol,Any}
end
function formatfigures(chunk, docformat::JMarkdown2HTML)
fignames = chunk.figures
caption = chunk.options[:fig_cap]
width = chunk.options[:out_width]
height = chunk.options[:out_height]
f_pos = chunk.options[:fig_pos]
f_env = chunk.options[:fig_env]
result = ""
figstring = ""
#Set size
attribs = ""
width == nothing || (attribs = "width=\"$width\"")
(attribs != "" && height != nothing ) && (attribs *= ",")
height == nothing || (attribs *= " height=\"$height\" ")
if f_env != nothing
result *= """<figure>\n"""
end
for fig = fignames
figstring *= """<img src="$fig" $attribs />\n"""
end
result *= figstring
if caption != nothing
result *= """
<figcaption>$caption</figcaption>
"""
end
if f_env != nothing
result *= "</figure>\n"
end
return result
end
const multimarkdown = MultiMarkdown("MultiMarkdown",
Dict{Symbol,Any}(
:codestart => "````julia",
@ -356,11 +399,11 @@ end
const formats = Dict{AbstractString, Any}("tex" => tex,
"texminted" => texminted,
"pandoc" => pandoc,
"md2html" => md2html,
"pandoc2html" => pdoc2html,
"md2pdf" => md2pdf,
"github" => github,
"multimarkdown" => multimarkdown,
"rst" => rst,
"asciidoc" => adoc,
"jmd2html" => jmd2html
"md2html" => md2html
)

View File

@ -5,15 +5,17 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=yes">
<style type="text/css">
{{{ :theme_css }}}
{{{ :highlight_css }}}
{{{ :themecss }}}
{{{ :highlightcss }}}
</style>
</HEAD>
<BODY>
<div class ="container">
<div class = "row">
<div class = "col-md-12 twelve columns">
{{{ :body }}}
</div>
</div>
</div>