diff --git a/src/display_methods.jl b/src/display_methods.jl index a28becf..76b4162 100644 --- a/src/display_methods.jl +++ b/src/display_methods.jl @@ -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) diff --git a/src/formatters.jl b/src/formatters.jl index 7cef86e..9154ab1 100644 --- a/src/formatters.jl +++ b/src/formatters.jl @@ -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")) diff --git a/templates/skeleton_css.css b/templates/skeleton_css.css index e23b596..f255919 100644 --- a/templates/skeleton_css.css +++ b/templates/skeleton_css.css @@ -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 { diff --git a/test/documents/markdown_output.jmd b/test/documents/markdown_output.jmd new file mode 100644 index 0000000..68769cc --- /dev/null +++ b/test/documents/markdown_output.jmd @@ -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 + +""") +``` diff --git a/test/documents/multimedia/rich_output.github.ref b/test/documents/multimedia/rich_output.github.ref index 6ecce14..48237c9 100644 --- a/test/documents/multimedia/rich_output.github.ref +++ b/test/documents/multimedia/rich_output.github.ref @@ -40,7 +40,12 @@ ca -
a
b
c
d
+----- +| a | +| b | +| c | +| d | +----- ````julia display(ca) @@ -49,8 +54,17 @@ display(x) -
a
b
c
d
-
11
22
33
+----- +| a | +| b | +| c | +| d | +----- +----- +| 1 | 1 | +| 2 | 2 | +| 3 | 3 | +----- ````julia julia> x @@ -78,5 +92,5 @@ m -

Some Markdown

-
+**Some Markdown** + diff --git a/test/formatter_test.jl b/test/formatter_test.jl index 60710f0..5870866 100644 --- a/test/formatter_test.jl +++ b/test/formatter_test.jl @@ -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

Small markdown sample

\n

Hello from code block.

\n
" +@test doc.chunks[2].rich_output == "\n
\n
" + +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"