Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rename mimewritable to showable #26089

Merged
merged 1 commit into from
Feb 21, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1367,6 +1367,7 @@ end
@deprecate IOBuffer(maxsize::Integer) IOBuffer(read=true, write=true, maxsize=maxsize)

@deprecate reprmime(mime, x) repr(mime, x)
@deprecate mimewritable(mime, x) showable(mime, x)

# PR #23332
@deprecate ^(x, p::Integer) Base.power_by_squaring(x,p)
Expand Down
2 changes: 1 addition & 1 deletion base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -875,10 +875,10 @@ export
istextmime,
MIME,
@MIME_str,
mimewritable,
popdisplay,
pushdisplay,
redisplay,
showable,
HTML,
Text,

Expand Down
24 changes: 12 additions & 12 deletions base/multimedia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ module Multimedia

export AbstractDisplay, display, pushdisplay, popdisplay, displayable, redisplay,
MIME, @MIME_str, istextmime,
mimewritable, TextDisplay
showable, TextDisplay

###########################################################################
# We define a singleton type MIME{mime symbol} for each MIME type, so
Expand All @@ -25,23 +25,26 @@ print(io::IO, ::MIME{mime}) where {mime} = print(io, mime)
# in order to provide a way to export T as a given mime type.

"""
mimewritable(mime, x)
showable(mime, x)

Returns a boolean value indicating whether or not the object `x` can be written as the given
`mime` type. (By default, this is determined automatically by the existence of the
corresponding [`show`](@ref) method for `typeof(x)`.)
Returns a boolean value indicating whether or not the object `x` can be written
as the given `mime` type.

(By default, this is determined automatically by the existence of the
corresponding [`show`](@ref) method for `typeof(x)`. Some types provide custom `showable`
methods; for example, if the available MIME formats depend on the *value* of `x`.)

# Examples
```jldoctest
julia> mimewritable(MIME("text/plain"), rand(5))
julia> showable(MIME("text/plain"), rand(5))
true

julia> mimewritable(MIME("img/png"), rand(5))
julia> showable("img/png", rand(5))
false
```
"""
mimewritable(::MIME{mime}, x) where {mime} =
hasmethod(show, Tuple{IO, MIME{mime}, typeof(x)})
showable(::MIME{mime}, x) where {mime} = hasmethod(show, Tuple{IO, MIME{mime}, typeof(x)})
showable(m::AbstractString, x) = showable(MIME(m), x)

"""
show(io, mime, x)
Expand Down Expand Up @@ -73,10 +76,7 @@ The first argument to `show` can be an [`IOContext`](@ref) specifying output for
See [`IOContext`](@ref) for details.
"""
show(stream, mime, x)

# it is convenient to accept strings instead of ::MIME
show(io::IO, m::AbstractString, x) = show(io, MIME(m), x)
mimewritable(m::AbstractString, x) = mimewritable(MIME(m), x)

"""
repr(mime, x; context=nothing)
Expand Down
4 changes: 2 additions & 2 deletions doc/src/base/io-network.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ Base.Multimedia.display
Base.Multimedia.redisplay
Base.Multimedia.displayable
Base.show(::Any, ::Any, ::Any)
Base.Multimedia.mimewritable
Base.Multimedia.showable
Base.repr(::Any, ::Any)
```

Expand All @@ -107,7 +107,7 @@ define a function `display(d::D, ::MIME"mime", x) = ...` that displays `x` as th
usually by calling [`show(io, mime, x)`](@ref) or [`repr(io, mime, x)`](@ref).
A `MethodError` should be thrown if `x` cannot be displayed
as that MIME type; this is automatic if one calls `show` or `repr`. Finally, one should define a function
`display(d::D, x)` that queries [`mimewritable(mime, x)`](@ref) for the `mime` types supported by `D`
`display(d::D, x)` that queries [`showable(mime, x)`](@ref) for the `mime` types supported by `D`
and displays the "best" one; a `MethodError` should be thrown if no supported MIME types are found
for `x`. Similarly, some subtypes may wish to override [`redisplay(d::D, ...)`](@ref Base.Multimedia.redisplay). (Again, one should
`import Base.display` to add new methods to `display`.) The return values of these functions are
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Markdown/src/render/rich.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ end

function bestmime(val)
for mime in ("text/html", "image/svg+xml", "image/png", "text/plain")
mimewritable(mime, val) && return MIME(Symbol(mime))
showable(mime, val) && return MIME(Symbol(mime))
end
error("Cannot render $val to Markdown.")
end
Expand Down