Closed jakobjpeters closed 2 months ago
Why would an AbstractString
subtype have a method to display as image/svg+xml
? That doesn't sound like a string?
The reason for this behavior is that it allows you to do things like display("image/svg+xml", "...raw SVG text as an ordinary string...")
and it will show an SVG image from the given string data interpreted as XML. (But we can probably avoid that behavior for the display_dict
if needed.)
My particular use case is for a TypstString
in Typstry.jl, which represents source text for the Typst typsetting system. This text can be compiled to PDF, PNG, and SVG via Typst_jll.jl, so there's a direct correspondence between a TypstString
and an SVG. Although the underlying implementation differs, I'd like typst"$ 1 / x $"
to be rendered in notebooks in a similar manner to L"$ \frac{1}{x} $"
.
Thank you for the clarification! Does display_dict
determine resulting output options? This comment seems to indicate so. If so, then is the solution to keep the current behavior for calls to limitstringmime
except from within display_dict
?
Yes, it would probably suffice to change the definition of limitstringmime
to:
function limitstringmime(mime::MIME, x, forcetext=false, mayberawtext=true)
change this line to
if israwtext(mime, x) && mayberawtext
and change this line to:
display_mimestring(m::MIME, x) = (m, limitstringmime(m, x, false, false))
Description
Users implementing
show
methods for anAbstractString
will have a broken display if the preferred MIME typeistextmime
. A motivating example is in Typstry.jl, which implementsshow
for"image/png"
and"image/svg+xml"
. Both of these methods work in Pluto.jl, but only"image/png"
works in IJulia.jl. This is because"image/svg+xml"
is preferred over"image/png"
, but this format assumes that anAbstractString
is "raw data". Instead of dispatching toshow
, it is returned as aString
.I don't really understand this assumption, why is it being used? The only thing I have found so far is the same assumption in
repr
and presume that's where it came from. A notable difference is that users are able to implementrepr
to patch in a fix.Possible Solutions
AbstractString
is "raw data"israwtext
String(repr(mime, x; context = InlineIOContext(buf)))
repr
, while preserving the preexisting behavior otherwise becauserepr
uses the same assumptionString
1. The output of
versioninfo()
IJulia v0.24.2
2. How you installed Julia
juliaup
3. A minimal working example (MWE), also known as a minimum reproducible example