diff --git a/src/Expanders.jl b/src/Expanders.jl index b7bedaa329..4ed851a004 100644 --- a/src/Expanders.jl +++ b/src/Expanders.jl @@ -607,6 +607,8 @@ function Selectors.runner(::Type{EvalBlocks}, node, page, doc) nothing elseif isa(result, Markdown.MD) convert(Node, result) + elseif isa(result, Documenter.UseShowMethods) + Node(result) else # TODO: we could handle the cases where the user provides some of the Markdown library # objects, like Paragraph. diff --git a/src/documents.jl b/src/documents.jl index 1dc27b1acf..83a19fd105 100644 --- a/src/documents.jl +++ b/src/documents.jl @@ -943,6 +943,11 @@ end MarkdownAST.iscontainer(::MultiOutput) = true MarkdownAST.can_contain(::MultiOutput, ::Union{MultiOutputElement,MarkdownAST.CodeBlock}) = true +struct UseShowMethods <: AbstractDocumenterBlock + element :: Dict{MIME, Any} + UseShowMethods(x) = new(display_dict(x)) +end + # In the SetupBlocks expander, we map @setup nodes to Markdown.MD() objects struct SetupNode <: AbstractDocumenterBlock name :: String diff --git a/src/html/HTMLWriter.jl b/src/html/HTMLWriter.jl index 6e8a77ae11..3c648dfaf5 100644 --- a/src/html/HTMLWriter.jl +++ b/src/html/HTMLWriter.jl @@ -1689,7 +1689,15 @@ function domify_doc(dctx::DCtx, node::Node) end function domify(dctx::DCtx, ::Node, evalnode::Documenter.EvalNode) - isnothing(evalnode.result) ? DOM.Node[] : domify(dctx, evalnode.result.children) + result = evalnode.result + ret = if result === Nothing + DOM.Node[] + elseif isempty(result.children) + domify(dctx, result) + else + domify(dctx, result.children) + end + return ret end # nothing to show for MetaNodes, so we just return an empty list @@ -2124,6 +2132,7 @@ end # Select the "best" representation for HTML output. domify(dctx::DCtx, node::Node, ::Documenter.MultiOutput) = domify(dctx, node.children) domify(dctx::DCtx, node::Node, moe::Documenter.MultiOutputElement) = Base.invokelatest(domify, dctx, node, moe.element) +domify(dctx::DCtx, node::Node, usm::Documenter.UseShowMethods) = Base.invokelatest(domify, dctx, node, usm.element) function domify(dctx::DCtx, node::Node, d::Dict{MIME,Any}) rawhtml(code) = Tag(Symbol("#RAW#"))(code) diff --git a/src/latex/LaTeXWriter.jl b/src/latex/LaTeXWriter.jl index 5424a72c9f..03a9d90d1a 100644 --- a/src/latex/LaTeXWriter.jl +++ b/src/latex/LaTeXWriter.jl @@ -403,7 +403,12 @@ end function latex(io::Context, node::Node, evalnode::Documenter.EvalNode) if evalnode.result !== nothing - latex(io, evalnode.result.children, toplevel = true) + result = evalnode.result + if isempty(result.children) + latex(io, result) + else + latex(io, result.children, toplevel = true) + end end end @@ -413,6 +418,9 @@ latex(io::Context, node::Node, ::Documenter.MultiOutput) = latex(io, node.childr function latex(io::Context, node::Node, moe::Documenter.MultiOutputElement) Base.invokelatest(latex, io, node, moe.element) end +function latex(io::Context, node::Node, usm::Documenter.UseShowMethods) + Base.invokelatest(latex, io, node, usm.element) +end function latex(io::Context, ::Node, d::Dict{MIME,Any}) filename = String(rand('a':'z', 7)) if haskey(d, MIME"image/png"())