XML documents should begin with an XML declaration (e.g. <?xml version="1.0" encoding="UTF-8"?>
). Therefore, when showing object in an XML-based format such as SVG (MIME"image/svg+xml"
), the XML declaration may be required.
On the other hand, an XML document "fragment" can be a sub-tree of another XML document. For example, SVG fragments can be contained in an (X)HTML document. Since the fragments are not documents, they must not have the XML declarations.
Therefore, I think it is useful to define a property like :no_xmldecl
.
The property is what the show
implementations within XML-based formats requires, and I don't think Julia itself needs to be involved in setting or clearing the property. In other words, what I'm looking for is the name and its documentation.
My two cents: I think this is actually broader than just SVG images or XML documents and is very relevant for Documenter. There are definitely cases where the exact meaning of the MIME can be ambiguous. E.g.:
Should the text/html
representation of a table be a full HTML page (with <html>
, <head>
etc.), or just a <table>
subtree?
Or text/latex
-- is that a full LaTeX document, just a fragment of a document, or just an equation (without delimiters)?
Of course, any of these interpretations can be valid -- it depends on the application. So controlling this with IOContext
properties feels like the right thing to do. But we would indeed need some documented conventions for that.
Regarding the SVG/XML case: a more generic :fragment
property might be an option too, that could then be re-used of other MIME types.
I think the intention is great and the idea is worth considering. But, I think it there is a problem.
When something is a requirement, e.g., the method must _not_ print HTML header, I think it's more composable to introduce a dedicated method rather than checking an optional context. If we try to do this with the context, calling show(IOContext(io, :fragment => true), "text/html", x)
only means "print x
, maybe with a header or maybe not." I don't think it's a useful system if we can't rely on the implementer to do the right thing.
I think it there is a problem.
I totally agree with you, @tkf. Therefore, I do not require any strict rules regarding the property. We have similar problems with common properties e.g. :color
, :compact
, but I don't think they are serious.
Since I want versatility rather than strictness, I am a big fan of :fragment
.:+1:
I guess, anyone implementing formatted show
would expect the outputs to look nice in Documenter.jl, IJulia, Juno, etc. On the other hand, I don't think there are many people who think that they must have the "same" result.
Cross-ref https://github.com/JuliaLang/julia/issues/5239 that covers a different example of the same issue.
Discussion of the intent for this future work at https://github.com/JuliaLang/julia/issues/14052 (implementation of this started in https://github.com/JuliaLang/julia/pull/27430)
Most helpful comment
Cross-ref https://github.com/JuliaLang/julia/issues/5239 that covers a different example of the same issue.
Discussion of the intent for this future work at https://github.com/JuliaLang/julia/issues/14052 (implementation of this started in https://github.com/JuliaLang/julia/pull/27430)