2016-12-13 21:02:42 +01:00
|
|
|
|
# Test rendering of doc chunks
|
|
|
|
|
content = """
|
|
|
|
|
# Test chunk
|
|
|
|
|
|
|
|
|
|
Test rendering \$\alpha\$
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
dchunk = Weave.DocChunk(content, 1, 1)
|
|
|
|
|
|
|
|
|
|
pformat = Weave.formats["github"]
|
|
|
|
|
f = Weave.format_chunk(dchunk, pformat.formatdict, pformat)
|
|
|
|
|
@test f == content
|
|
|
|
|
|
|
|
|
|
docformat = Weave.formats["md2html"]
|
2018-01-07 19:19:59 +01:00
|
|
|
|
f_check = "<h1>Test chunk</h1>\n<p>Test rendering <span class=\"math\">\$\alpha\$</span></p>\n"
|
2016-12-13 21:02:42 +01:00
|
|
|
|
f = Weave.format_chunk(dchunk, docformat.formatdict, docformat)
|
|
|
|
|
@test f_check == f
|
|
|
|
|
|
2016-12-15 15:13:24 +01:00
|
|
|
|
# Test with actual doc
|
|
|
|
|
|
2020-05-10 06:20:44 +02:00
|
|
|
|
parsed = Weave.WeaveDoc("documents/chunk_options.noweb")
|
2020-05-08 19:31:45 +02:00
|
|
|
|
doc = run_doc(parsed, doctype = "md2html")
|
2016-12-14 23:24:26 +01:00
|
|
|
|
|
2017-03-13 15:12:57 +01:00
|
|
|
|
c_check = "<pre class='hljl'>\n<span class='hljl-n'>x</span><span class='hljl-t'> </span><span class='hljl-oB'>=</span><span class='hljl-t'> </span><span class='hljl-p'>[</span><span class='hljl-ni'>12</span><span class='hljl-p'>,</span><span class='hljl-t'> </span><span class='hljl-ni'>10</span><span class='hljl-p'>]</span><span class='hljl-t'>\n</span><span class='hljl-nf'>println</span><span class='hljl-p'>(</span><span class='hljl-n'>y</span><span class='hljl-p'>)</span>\n</pre>\n"
|
2016-12-15 15:13:24 +01:00
|
|
|
|
doc.format.formatdict[:theme] = doc.highlight_theme
|
2016-12-19 17:42:00 +01:00
|
|
|
|
c = Weave.format_code(doc.chunks[3].content, doc.format)
|
2016-12-13 21:02:42 +01:00
|
|
|
|
@test c_check == c
|
|
|
|
|
|
2017-03-13 15:12:57 +01:00
|
|
|
|
o_check = "\nprintln(x)\n"
|
|
|
|
|
o = Weave.format_output(doc.chunks[4].content, doc.format)
|
2016-12-13 21:02:42 +01:00
|
|
|
|
@test o_check == o
|
2016-12-15 15:13:24 +01:00
|
|
|
|
|
|
|
|
|
doc.template = "templates/mini.tpl"
|
|
|
|
|
rendered = Weave.render_doc("Hello", doc, doc.format)
|
|
|
|
|
@test rendered == "\nHello\n"
|
|
|
|
|
|
|
|
|
|
# Tex format
|
2020-05-10 06:20:44 +02:00
|
|
|
|
parsed = Weave.WeaveDoc("documents/chunk_options.noweb")
|
2020-05-08 19:31:45 +02:00
|
|
|
|
doc = run_doc(parsed, doctype = "md2tex")
|
2016-12-15 15:13:24 +01:00
|
|
|
|
|
2018-07-25 10:22:12 +02:00
|
|
|
|
c_check = "\\begin{lstlisting}\n(*@\\HLJLnf{println}@*)(*@\\HLJLp{(}@*)(*@\\HLJLn{x}@*)(*@\\HLJLp{)}@*)\n\\end{lstlisting}\n"
|
2016-12-15 15:13:24 +01:00
|
|
|
|
doc.format.formatdict[:theme] = doc.highlight_theme
|
2017-03-13 15:12:57 +01:00
|
|
|
|
c = Weave.format_code(doc.chunks[4].content, doc.format)
|
2016-12-15 15:13:24 +01:00
|
|
|
|
@test c_check == c
|
|
|
|
|
|
2017-03-13 15:12:57 +01:00
|
|
|
|
o_check = "\nx = [12, 10]\nprintln(y)\n"
|
|
|
|
|
o = Weave.format_output(doc.chunks[3].content, doc.format)
|
2016-12-15 15:13:24 +01:00
|
|
|
|
@test o_check == o
|
|
|
|
|
|
|
|
|
|
doc.template = "templates/mini.tpl"
|
|
|
|
|
rendered = Weave.render_doc("Hello", doc, doc.format)
|
|
|
|
|
@test rendered == "\nHello\n"
|
|
|
|
|
|
|
|
|
|
# Test header parsing and stripping
|
|
|
|
|
header = """
|
|
|
|
|
---
|
|
|
|
|
title : Test block
|
|
|
|
|
author : Matti Pastell
|
|
|
|
|
---
|
|
|
|
|
|
|
|
|
|
# Actual header
|
|
|
|
|
|
|
|
|
|
and some text
|
|
|
|
|
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
dchunk = Weave.DocChunk(header, 1, 1)
|
|
|
|
|
h = Weave.parse_header(dchunk)
|
|
|
|
|
h_ref = Dict("author" => "Matti Pastell", "title" => "Test block")
|
|
|
|
|
@test h_ref == h
|
|
|
|
|
|
2020-04-17 16:14:39 +02:00
|
|
|
|
Weave.strip_header!(dchunk, "md2html")
|
2016-12-15 15:13:24 +01:00
|
|
|
|
h_ref = """
|
|
|
|
|
# Actual header
|
|
|
|
|
|
|
|
|
|
and some text
|
|
|
|
|
|
|
|
|
|
"""
|
2020-04-17 16:14:39 +02:00
|
|
|
|
@test dchunk.content[1].content == h_ref
|
2019-02-25 23:09:40 +01:00
|
|
|
|
|
|
|
|
|
# Test wrapping
|
|
|
|
|
|
|
|
|
|
cows = repeat("🐄", 100)
|
|
|
|
|
testcows = """
|
|
|
|
|
🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄
|
|
|
|
|
🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄"""
|
|
|
|
|
|
|
|
|
|
wcows = Weave.wrapline(cows)
|
|
|
|
|
|
|
|
|
|
@test wcows == testcows
|
|
|
|
|
@test length(split(wcows, "\n")[1]) == 75
|
|
|
|
|
@test length(split(wcows, "\n")[2]) == 25
|
2019-02-26 16:38:28 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
tfied = "\\ensuremath{\\bm{\\mathrm{L}}} \\ensuremath{\\bm{\\mathfrak{F}}} \\ensuremath{\\bm{\\iota}} \\ensuremath{\\mathfrak{A}} \\ensuremath{\\bm{\\varTheta}}"
|
|
|
|
|
|
|
|
|
|
@test Weave.uc2tex("𝐋 𝕱 𝛊 𝔄 𝚹") == tfied
|
2019-02-27 14:03:33 +01:00
|
|
|
|
|
|
|
|
|
# Test markdown output from chunks
|
2020-05-10 06:20:44 +02:00
|
|
|
|
parsed = Weave.WeaveDoc("documents/markdown_output.jmd")
|
2020-05-08 19:31:45 +02:00
|
|
|
|
doc = run_doc(parsed, doctype = "md2html")
|
2019-02-27 14:03:33 +01:00
|
|
|
|
@test doc.chunks[1].rich_output == "\n<div class=\"markdown\"><h3>Small markdown sample</h3>\n<p><strong>Hello</strong> from <code>code</code> block.</p>\n</div>"
|
|
|
|
|
@test doc.chunks[2].rich_output == "\n<div class=\"markdown\"><ul>\n<li><p>one</p>\n</li>\n<li><p>two</p>\n</li>\n<li><p>three</p>\n</li>\n</ul>\n</div>"
|
|
|
|
|
|
2020-05-08 19:31:45 +02:00
|
|
|
|
ldoc = run_doc(parsed, doctype = "md2tex")
|
2019-02-27 14:03:33 +01:00
|
|
|
|
@test ldoc.chunks[1].rich_output == "\n\\subsubsection{Small markdown sample}\n\\textbf{Hello} from \\texttt{code} block.\n\n"
|
|
|
|
|
@test ldoc.chunks[2].rich_output == "\n\\begin{itemize}\n\\item one\n\n\n\\item two\n\n\n\\item three\n\n\\end{itemize}\n"
|
|
|
|
|
|
2020-05-08 19:31:45 +02:00
|
|
|
|
mdoc = run_doc(parsed, doctype = "github")
|
2019-02-27 14:03:33 +01:00
|
|
|
|
@test mdoc.chunks[1].rich_output == "\n\n### Small markdown sample\n\n**Hello** from `code` block.\n\n"
|
|
|
|
|
@test mdoc.chunks[2].rich_output == "\n\n* one\n* two\n* three\n\n"
|
2019-09-05 10:13:49 +02:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
# Test disable escaping of unicode
|
|
|
|
|
content = """
|
|
|
|
|
# Test chunk
|
|
|
|
|
α
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
dchunk = Weave.DocChunk(content, 1, 1)
|
|
|
|
|
|
|
|
|
|
pformat = Weave.formats["md2tex"]
|
|
|
|
|
|
|
|
|
|
f = Weave.format_chunk(dchunk, pformat.formatdict, pformat)
|
|
|
|
|
@test f == "\\section{Test chunk}\n\\ensuremath{\\alpha}\n\n"
|
2019-10-15 21:48:05 +02:00
|
|
|
|
pformat.formatdict[:keep_unicode] = true
|
|
|
|
|
f = Weave.format_chunk(dchunk, pformat.formatdict, pformat)
|
2019-09-05 10:13:49 +02:00
|
|
|
|
@test f == "\\section{Test chunk}\nα\n\n"
|
2019-10-15 21:48:05 +02:00
|
|
|
|
|
|
|
|
|
|
2020-05-09 15:33:58 +02:00
|
|
|
|
str = """
|
2019-10-15 21:48:05 +02:00
|
|
|
|
```julia
|
|
|
|
|
α = 10
|
|
|
|
|
```
|
|
|
|
|
"""
|
|
|
|
|
|
2020-05-09 15:33:58 +02:00
|
|
|
|
let
|
|
|
|
|
doc = run_doc(mock_doc(str), doctype = "md2tex")
|
|
|
|
|
@test occursin(Weave.uc2tex("α"), Weave.format(doc))
|
|
|
|
|
@test !occursin("α", Weave.format(doc))
|
|
|
|
|
end
|
2019-10-15 21:48:05 +02:00
|
|
|
|
|
2020-05-09 15:33:58 +02:00
|
|
|
|
let
|
|
|
|
|
doc = run_doc(mock_doc(str), doctype = "md2tex",latex_keep_unicode = true)
|
|
|
|
|
@test occursin("α", Weave.format(doc))
|
|
|
|
|
@test !occursin(Weave.uc2tex("α"), Weave.format(doc))
|
|
|
|
|
end
|