Converts Livebook .livemd notebooks into executable Elixir scripts.
This module is the second stage in the LivebookTest pipeline:
Discovery → **Exporter** → DependencyPatcher → Runner → ReportIt uses Livebook.live_markdown_to_elixir/1 to transform the
Markdown-based Livebook format into a standalone .exs script
that can be executed by the Elixir runtime.
How exporting works
- Read the
.livemdfile content - Pass it to
Livebook.live_markdown_to_elixir/1 - Receive an Elixir script string
- Optionally write the script to a temporary file for execution
Examples
iex> {:ok, script} = LivebookTest.Exporter.to_elixir("examples/basic.livemd")
iex> is_binary(script)
true
Summary
Types
Export result
Functions
Converts a .livemd notebook file to an Elixir script string.
Converts notebook content (already read) to an Elixir script string.
Exports a notebook to a temporary .exs file.
Exports notebook content to a temporary .exs file.
Types
Functions
@spec to_elixir(Path.t()) :: export_result()
Converts a .livemd notebook file to an Elixir script string.
Reads the file and passes its content through
Livebook.live_markdown_to_elixir/1.
Examples
iex> {:ok, script} = LivebookTest.Exporter.to_elixir("examples/basic.livemd")
iex> String.contains?(script, "IO")
true
@spec to_elixir_from_string(String.t()) :: export_result()
Converts notebook content (already read) to an Elixir script string.
Useful when the notebook content has already been read, or when working with in-memory notebook strings.
Examples
iex> content = "# \\n\\n## Section\\n\\n```elixir\\nIO.puts(:hello)\\n```"
iex> {:ok, _script} = LivebookTest.Exporter.to_elixir_from_string(content)
Exports a notebook to a temporary .exs file.
Converts the notebook and writes the resulting script to a temporary file, returning the path. The caller is responsible for cleaning up the file after use.
Examples
iex> {:ok, path} = LivebookTest.Exporter.to_temp_file("examples/basic.livemd")
iex> String.ends_with?(path, ".exs")
true
Exports notebook content to a temporary .exs file.
Like to_temp_file/1 but accepts already-read content.
Examples
iex> content = "# \\n\\n## Section\\n\\n```elixir\\n1 + 1\\n```"
iex> {:ok, path} = LivebookTest.Exporter.to_temp_file_from_string(content)
iex> File.exists?(path)
true