# `Choreo.Livebook`
[🔗](https://github.com/code-shoily/choreo/blob/v0.14.1/lib/choreo/livebook.ex#L1)

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.

# `evaluate_blocks`

```elixir
@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 to headless mocks.
* Replaces visual renderers with `Kernel.inspect` so they return plain values.

Returns `:ok` on success or `{:error, exception, stacktrace}` on failure.

# `extract_elixir_blocks`

```elixir
@spec extract_elixir_blocks(String.t()) :: [String.t()]
```

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.

# `parse_sections`

```elixir
@spec parse_sections(String.t()) :: [%{section: String.t(), content: String.t()}]
```

Parses markdown headers and their contents, skipping lines inside fenced
code blocks so that commented Elixir code is not mistaken for a section.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
