livebook/lib/live_book/notebook/cell.ex
Jonatan Kłosko 6ac7f94897
Define notebook file format (#27)
* Initial file import/export

* Add renderer tests

* Refactor renderer

* Depend only on EarmarkParser

* Add test for export

* Add import tests

* Improve import

* Document the ExMd file format

* Rename ExMd to ExMarkdown

* Rename ExMarkdown to LiveMarkdown

* Build iodata when exporting a notebook

* Persist metadata as a single JSON object

* Move Markdown to LiveMarkdown.MarkdownHelpers

* Make LiveMarkdown private

* Always move primary heading to the top during import

* Hint the user not to use heading 1 and 2

* Return a list of messages from the import function

* Update headings warning

* Add import and export test for non-elixir snippets

* Merge markdown renderer into MarkdownHelpers

* Add import messages on AST rewrites
2021-02-16 18:39:52 +01:00

38 lines
883 B
Elixir

defmodule LiveBook.Notebook.Cell do
@moduledoc false
# Data structure representing a single cell in a notebook.
#
# A cell is the smallest unit of work in a notebook.
# It primarly consists of text content that the user can edit
# and may potentially produce some output (e.g. during code evaluation).
defstruct [:id, :type, :source, :outputs, :metadata]
alias LiveBook.Utils
@type id :: Utils.id()
@type type :: :markdown | :elixir
@type t :: %__MODULE__{
id: id(),
type: type(),
source: String.t(),
outputs: list(),
metadata: %{String.t() => term()}
}
@doc """
Returns an empty cell of the given type.
"""
@spec new(type()) :: t()
def new(type) do
%__MODULE__{
id: Utils.random_id(),
type: type,
source: "",
outputs: [],
metadata: %{}
}
end
end