Shared helpers for parsing and headlessly evaluating Choreo Livebooks.
Used by Mix.Tasks.Choreo.TestLivebooks and Choreo.MCP so that both
tools validate notebooks with the same parser, mock suite, and evaluation
semantics.
Summary
Functions
Evaluates the extracted Elixir blocks in a headless environment.
Extracts elixir code blocks from a Livebook markdown string.
Parses markdown headers and their contents, skipping lines inside fenced code blocks so that commented Elixir code is not mistaken for a section.
Functions
@spec evaluate_blocks([String.t()]) :: :ok | {:error, struct(), Exception.stacktrace()}
Evaluates the extracted Elixir blocks in a headless environment.
- Strips
Mix.install([...])calls (the host already has dependencies). - Redirects
Kino.*calls toChoreo.Livebook.KinoMock. - Replaces visual renderers with
Kernel.inspectso they return plain values.
Returns :ok on success or {:error, exception, stacktrace} on failure.
Extracts elixir code blocks from a Livebook markdown string.
The parser is nested-fence aware: it matches the exact opening backtick sequence and only closes the block on the same sequence. This avoids truncating blocks that contain triple-backtick strings.
Parses markdown headers and their contents, skipping lines inside fenced code blocks so that commented Elixir code is not mistaken for a section.