Skip to content

Commit

Permalink
Exclude HTML and Markdown by default
Browse files Browse the repository at this point in the history
  • Loading branch information
tkf committed Feb 3, 2019
1 parent 9dda57d commit 3ad12b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
````
12 changes: 8 additions & 4 deletions src/ElectronDisplay.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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}()

Expand Down

0 comments on commit 3ad12b0

Please sign in to comment.