View Source Kino.Render protocol (Kino v0.11.3)
Protocol defining term formatting in the context of Livebook.
Link to this section Summary
Link to this section Types
Link to this section Functions
Transforms the given value into a Livebook-compatible output.
For detailed description of the output format see
When implementing the protocol for custom struct, you generally do
not need to worry about the output format. Instead, you can compose
built-in kinos and call
Kino.Render.to_livebook/1 to get the
For example, if we wanted to render a custom struct as a mermaid graph, we could do this:
defimpl Kino.Render, for: Graph do def to_livebook(graph) do source = Graph.to_mermaid(graph) mermaid_kino = Kino.Mermaid.new(source) Kino.Render.to_livebook(mermaid_kino) end end
In many cases it is useful to show the default inspect representation alongside our custom visual representation. For this, we can use tabs:
defimpl Kino.Render, for: Graph do def to_livebook(graph) do source = Graph.to_mermaid(graph) mermaid_kino = Kino.Mermaid.new(source) inspect_kino = Kino.Inspect.new(image) kino = Kino.Layout.tabs(Graph: mermaid_kino, Raw: inspect_kino) Kino.Render.to_livebook(kino) end end