Add tests for inline code

pull/202/head
Matti Pastell 2019-03-11 13:39:21 +02:00
parent 35addd2b50
commit 83e2e0ae20
5 changed files with 97 additions and 1 deletions

View File

@ -1,3 +1,5 @@
import Mustache
#Default options
const defaultParams =
Dict{Symbol,Any}(:storeresults => false,
@ -114,7 +116,7 @@ function header_args(doc::WeaveDoc, out_path, mod, fig_ext, fig_path,
cache = Symbol(getvalue(args, "cache", cache))
throw_errors = getvalue(args, "throw_errors", throw_errors)
template = getvalue(args, "template", template)
if template != nothing && !isempty(template)
if template != nothing && !isa(template, Mustache.MustacheTokens) && !isempty(template)
template = joinpath(dirname(doc.source), template)
end
highlight_theme = getvalue(args, "highlight_theme", highlight_theme)

View File

@ -0,0 +1,23 @@
<div class="Random plot">
<p>Some inline output</p>
<pre class='hljl'>
<span class='hljl-nf'>println</span><span class='hljl-p'>(</span><span class='hljl-s'>&quot;Testing output&quot;</span><span class='hljl-p'>)</span>
</pre>
<pre class="output">
Testing output
</pre>
</div>

View File

@ -0,0 +1,23 @@
\begin{frame}[fragile]
\frametitle{Random plot}
Some inline output
\begin{lstlisting}
(*@\HLJLnf{println}@*)(*@\HLJLp{(}@*)(*@\HLJLs{"Testing output"}@*)(*@\HLJLp{)}@*)
\end{lstlisting}
\begin{lstlisting}
Testing output
\end{lstlisting}
\end{frame}

View File

@ -0,0 +1,31 @@
---
title : A minimal beamer example using Weave markdown
author : Matti Pastell
options :
out_path : inline
---
```julia; echo=false
struct Begin
text
title
end
struct End
text
end
Base.show(io::IO, m::MIME"text/latex", b::Begin) = write(io, "\\begin{$(b.text)}[fragile]\n\\frametitle{$(b.title)}\n")
Base.show(io::IO, m::MIME"text/latex", e::End) = write(io, "\\end{$(e.text)}")
Base.show(io::IO, m::MIME"text/html", b::Begin) = write(io, "<div class=\"$(b.title)\">\n")
Base.show(io::IO, m::MIME"text/html", e::End) = write(io, "</div>")
```
! Begin("frame", "Random plot")
Some inline `j print("output")`
```julia
println("Testing output")
```
! End("frame")

View File

@ -1,4 +1,7 @@
using Weave, Test
using Mustache
# Test parsing
doc = """
@ -24,3 +27,17 @@ chunk = Weave.parse_doc(doc, Weave.input_formats["markdown"])[1]
chunknw = Weave.parse_doc(doc, Weave.input_formats["noweb"])[1]
@test all([chunknw.content[i].content == chunk.content[i].content for i in 1:7])
# Test with document
tpl = mt"""
{{{ :body }}}
"""
out = weave(joinpath(@__DIR__, "documents", "markdown_beamer.jmd"), doctype="md2html", template=tpl)
@test read(out, String) == read(out*".ref", String)
rm(out)
out = weave(joinpath(@__DIR__, "documents", "markdown_beamer.jmd"), doctype="md2tex", template=tpl)
@test read(out, String) == read(out*".ref", String)
rm(out)