DisplayAs.jl

DisplayAs.DisplayAsModule

DisplayAs

Stable Dev Run tests Codecov Aqua QA GitHub last commit

DisplayAs.jl provides functions to show objects in a chosen MIME type.

julia> using DisplayAs
       using Markdown

julia> md_as_html = Markdown.parse("hello") |> DisplayAs.HTML;

julia> showable("text/html", md_as_html)
true

julia> showable("text/markdown", md_as_html)
false

julia> md_as_md = Markdown.parse("hello") |> DisplayAs.MD;

julia> showable("text/html", md_as_md)
false

julia> showable("text/markdown", md_as_md)
true

It is also possible to use nesting in order to allow the object to be displayed as multiple MIME types:

julia> md_as_html_or_text = Markdown.parse("hello") |> DisplayAs.HTML |> DisplayAs.Text;

julia> showable("text/html", md_as_html_or_text)
true

julia> showable("text/plain", md_as_html_or_text)
true

julia> showable("text/markdown", md_as_html_or_text)
false
source
DisplayAs.CSVType
DisplayAs.CSV(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type text/csv. That is to say, display(DisplayAs.CSV(x)) is equivalent to display("text/csv", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.EPSType
DisplayAs.EPS(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type application/eps. That is to say, display(DisplayAs.EPS(x)) is equivalent to display("application/eps", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.GIFType
DisplayAs.GIF(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type image/gif. That is to say, display(DisplayAs.GIF(x)) is equivalent to display("image/gif", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.HTMLType
DisplayAs.HTML(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type text/html. That is to say, display(DisplayAs.HTML(x)) is equivalent to display("text/html", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.JPEGType
DisplayAs.JPEG(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type image/jpeg. That is to say, display(DisplayAs.JPEG(x)) is equivalent to display("image/jpeg", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.JSONType
DisplayAs.JSON(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type application/json. That is to say, display(DisplayAs.JSON(x)) is equivalent to display("application/json", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.LaTeXType
DisplayAs.LaTeX(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type text/latex. That is to say, display(DisplayAs.LaTeX(x)) is equivalent to display("text/latex", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.MDType
DisplayAs.MD(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type text/markdown. That is to say, display(DisplayAs.MD(x)) is equivalent to display("text/markdown", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.PDFType
DisplayAs.PDF(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type application/pdf. That is to say, display(DisplayAs.PDF(x)) is equivalent to display("application/pdf", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.PNGType
DisplayAs.PNG(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type image/png. That is to say, display(DisplayAs.PNG(x)) is equivalent to display("image/png", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.PSType
DisplayAs.PS(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type application/postscript. That is to say, display(DisplayAs.PS(x)) is equivalent to display("application/postscript", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.SVGType
DisplayAs.SVG(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type image/svg+xml. That is to say, display(DisplayAs.SVG(x)) is equivalent to display("image/svg+xml", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.ShowableType
Showable{mime <: MIME}

Examples

julia> using DisplayAs

julia> DisplayAs.Showable{MIME"text/html"} === DisplayAs.HTML
true

julia> using Markdown

julia> md = Markdown.parse("hello");

julia> showable("text/html", md)
true

julia> showable("text/markdown", md)
true

julia> showable("text/html", DisplayAs.HTML(md))
true

julia> showable("text/markdown", DisplayAs.HTML(md))
false

julia> showable("text/html", DisplayAs.MD(md))
false

julia> showable("text/markdown", DisplayAs.MD(md))
true
source
DisplayAs.TSVType
DisplayAs.TSV(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type text/tab-separated-values. That is to say, display(DisplayAs.TSV(x)) is equivalent to display("text/tab-separated-values", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.TextType
DisplayAs.Text(x; options...)

Wrap an object x in another object that prefers to be displayed as MIME type text/plain. That is to say, display(DisplayAs.Text(x)) is equivalent to display("text/plain", x) (except some corner cases).

If x is already of type Showable the result will allow displaying in both the original and the new MIME type.

The named arguments options are passed to the 3-argument show method of x.

See also Showable.

source
DisplayAs.setcontextMethod
DisplayAs.setcontext(obj, kvs::Pair...)

Bundle arguments for IOContext with the object x.

Examples

julia> import DisplayAs

julia> data = rand(2, 2)
2×2 Array{Float64,2}:
 0.786992  0.576265
 0.321868  0.791263

julia> DisplayAs.setcontext(data, :compact => false)
2×2 Array{Float64,2}:
 0.7869920812675713   0.5762653628115182
 0.32186846202784314  0.791263230914472

See also DisplayAs.withcontext.

source
DisplayAs.unlimitedMethod
DisplayAs.unlimited(x)

Unlimit display size of object x. Useful for, e.g., printing all contents of dataframes in a Jupyter notebook.

Examples

julia> using DisplayAs, VegaDatasets

julia> data = dataset("cars");

julia> data |> DisplayAs.unlimited
source
DisplayAs.withcontextMethod
DisplayAs.withcontext(kvs::Pair...)

Convenience method equivalent to obj -> DisplayAs.setcontext(obj, kvs...) useful for "piping".

Examples

julia> import DisplayAs

julia> rand(2, 2) |> DisplayAs.withcontext(:compact => false)
2×2 Array{Float64,2}:
 0.7869920812675713   0.5762653628115182
 0.32186846202784314  0.791263230914472

See also DisplayAs.setcontext.

source
DisplayAs.@mime_strMacro
mime"..." :: Type{<:Showable}

Examples

julia> using DisplayAs

julia> DisplayAs.mime"text/plain" === DisplayAs.Text
true
source
DisplayAs.Raw.ShowableType
DisplayAs.Raw.Showable{mime}(bytes::Vector{UInt8})

An object that prints bytes for rendering show on mime; i.e., this object defines show(io::IO, ::mime, DisplayAs.Raw.Showable{mime}(bytes)) as write(io, bytes).

source
DisplayAs.Raw.@mime_strMacro
DisplayAs.Raw.mime"..." :: Type{<:DisplayAs.Raw.Showable}

Examples

julia> using DisplayAs

julia> DisplayAs.Raw.mime"text/plain" === DisplayAs.Raw.Text
true
source