diff --git a/README.md b/README.md index 01b6dd5..9ce6356 100644 --- a/README.md +++ b/README.md @@ -20,7 +20,7 @@ Pkg.add("ElectronDisplay") As soon as you load the package with ``using ElectronDisplay``, it will start to show plots that have the correct ``show`` methods in an electron window. -`ElectronDisplay` also exports a function `electrondisplay`. You can use `electrondisplay(x)` to show `x` explicitly in `ElectronDisplay` (e.g., when another display has higher precedence). You can also use `electrondisplay(mime, x)` to specify a MIME to be used. +`ElectronDisplay` also exports a function `electrondisplay`. You can use `electrondisplay(x)` to show `x` explicitly in `ElectronDisplay` (e.g., when another display has higher precedence). You can also use `electrondisplay(mime, x)` to specify a MIME to be used. For example, to read a docstring of `reduce` in `ElectronDisplay`, you can use `electrondisplay(@doc reduce)`. ## Configuration @@ -31,9 +31,9 @@ using ElectronDisplay ElectronDisplay.CONFIG.single_window = true ```` -To control objects to be handled by `ElectronDisplay`, you can set `ElectronDisplay.CONFIG.showable` (which defaults to `Base.showable`). For example, to avoid showing help output with `?thing` to `ElectronDisplay`, you can use: +To control objects to be handled by `ElectronDisplay`, you can set `ElectronDisplay.CONFIG.showable`. By default, `ElectronDisplay` does not show markdown or HTML output. To show everything in `ElectronDisplay` whenever it's supported, you can use: ````julia using Markdown -ElectronDisplay.CONFIG.showable = (m, x) -> !(x isa Markdown.MD) && showable(m, x) +ElectronDisplay.CONFIG.showable = showable ```` diff --git a/src/ElectronDisplay.jl b/src/ElectronDisplay.jl index fcbe28f..8c7b9be 100644 --- a/src/ElectronDisplay.jl +++ b/src/ElectronDisplay.jl @@ -6,6 +6,8 @@ using Electron, Base64 struct ElectronDisplayType <: Base.AbstractDisplay end +electron_showable(m, x) = m ∉ ("text/html", "text/markdown") && showable(m, x) + mutable struct ElectronDisplayConfig showable single_window::Bool @@ -16,15 +18,17 @@ end Configuration for ElectronDisplay. -* `showable = Base.showable`: A function with signature - `showable(mime::String, x::Any) :: Bool`. This determines if object - `x` is displayed by `ElectronDisplay`. Default to `Base.showable`. +* `showable`: A callable with signature `showable(mime::String, + x::Any) :: Bool`. This determines if object `x` is displayed by + `ElectronDisplay`. Default is to return `false` if `mime` is + `"text/html"` or `"text/markdown"` and otherwise fallbacks to + `Base.showable(mime, x)`. * `single_window::Bool = false`: If `true`, reuse existing window for displaying a new content. If `false` (default), create a new window for each display. """ -const CONFIG = ElectronDisplayConfig(showable, false) +const CONFIG = ElectronDisplayConfig(electron_showable, false) const _window = Ref{Window}()