Render markdown output in md2* formats. Fixes #156

pull/185/merge
Matti Pastell 2019-02-27 15:03:33 +02:00
parent e52083c42a
commit 8d1bb63b0a
6 changed files with 80 additions and 12 deletions

View File

@ -106,7 +106,16 @@ end
#Catch "rich_output"
function Base.display(report::Report, m::MIME"text/markdown", data)
s = repr(m, data)
report.rich_output *= "\n" * s
# Convert to "richer" type of possible
for m in report.mimetypes
if m == "text/html" || m == "text/latex"
display(Markdown.parse(s))
break
elseif m == "text/markdown"
report.rich_output *= "\n" * s
break
end
end
end
function Base.display(report::Report, m::MIME"text/latex", data)

View File

@ -88,6 +88,7 @@ const github = GithubMarkdown("Github markdown",
:outputend=> "````\n\n",
:fig_ext=> ".png",
:extension=> "md",
:mimetypes => ["image/png", "image/svg+xml", "image/jpg", "text/markdown", "text/plain"],
:doctype=> "github"
))
@ -144,8 +145,8 @@ const md2tex = JMarkdown2tex("Julia markdown to latex", Dict{Symbol,Any}(
:fig_ext=> ".pdf",
:extension=> "tex",
:out_width => "\\linewidth",
:mimetypes => ["application/pdf", "image/png", "image/jpg",
"text/latex", "text/plain"],
:mimetypes => ["application/pdf", "image/png", "image/jpg", "text/latex",
"text/markdown", "text/plain"],
:doctype=> "md2tex"))

View File

@ -500,16 +500,15 @@ pre {
}
pre.hljl {
margin: 0 0 10px;
display: block;
background: #f5f5f5;
border-radius: 4px;
padding : 5px;
}
pre.output {
background: #ffffff;
/* matching hard-coded values in Highlights.jl */
margin : 5px;
padding : 5px;
}
pre.julia-error {

View File

@ -0,0 +1,31 @@
```julia
display("text/markdown",
"""
### Small markdown sample
**Hello** from `code` block.
""")
```
```julia
struct Dummy
s::String
end
function Base.show(io::IO, m::MIME"text/markdown", d::Dummy)
print(io, d.s)
end
Dummy("""
* one
* two
* three
""")
```

View File

@ -40,7 +40,12 @@ ca
<table><tr><td>a</td></tr><tr><td>b</td></tr><tr><td>c</td></tr><tr><td>d</td></tr></table>
-----
| a |
| b |
| c |
| d |
-----
````julia
display(ca)
@ -49,8 +54,17 @@ display(x)
<table><tr><td>a</td></tr><tr><td>b</td></tr><tr><td>c</td></tr><tr><td>d</td></tr></table>
<table><tr><td>1</td><td>1</td></tr><tr><td>2</td><td>2</td></tr><tr><td>3</td><td>3</td></tr></table>
-----
| a |
| b |
| c |
| d |
-----
-----
| 1 | 1 |
| 2 | 2 |
| 3 | 3 |
-----
````julia
julia> x
@ -78,5 +92,5 @@ m
<div class="markdown"><p><strong>Some Markdown</strong></p>
</div>
**Some Markdown**

View File

@ -81,7 +81,6 @@ and some text
"""
@test htext.content[1].content == h_ref
# Test wrapping
cows = repeat("🐄", 100)
@ -90,6 +89,7 @@ testcows = """
🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄🐄"""
wcows = Weave.wrapline(cows)
println(wcows)
@test wcows == testcows
@test length(split(wcows, "\n")[1]) == 75
@ -99,3 +99,17 @@ wcows = Weave.wrapline(cows)
tfied = "\\ensuremath{\\bm{\\mathrm{L}}} \\ensuremath{\\bm{\\mathfrak{F}}} \\ensuremath{\\bm{\\iota}} \\ensuremath{\\mathfrak{A}} \\ensuremath{\\bm{\\varTheta}}"
@test Weave.uc2tex("𝐋 𝕱 𝛊 𝔄 𝚹") == tfied
# Test markdown output from chunks
parsed = Weave.read_doc("documents/markdown_output.jmd")
doc = Weave.run(parsed, doctype = "md2html")
@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>"
ldoc = Weave.run(parsed, doctype = "md2tex")
@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"
mdoc = Weave.run(parsed, doctype = "github")
@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"