# `WardrikDaemon.Console.Markdown`

Renders streamed markdown a line at a time.

Text arrives a token at a time and must reach the screen before the document is finished, so
this renders lines, not documents. `push/2` takes what arrived and returns the lines now
complete. It keeps the rest:

    {lines, buffer} = WardrikDaemon.Console.Markdown.push(WardrikDaemon.Console.Markdown.new(), "# Title\nsome ")
    {lines, buffer} = WardrikDaemon.Console.Markdown.push(buffer, "prose\n")
    {lines, _buffer} = WardrikDaemon.Console.Markdown.flush(buffer)

A line is `Owl.Data`. Two constructs span lines:

  * a fenced code block - the buffer tracks whether it's inside one.
  * a table - its rows are held back until the line after it arrives. They come back together
    as one `WardrikDaemon.Console.Table`, which whoever draws it lays out at its own width.

`tail/1` returns the unfinished line, for a screen that shows text before its line is complete.

Nothing here wraps. Whoever draws a line wraps it at its own width, so a resized screen can wrap
it again.

# `line`

```elixir
@type line() :: Owl.Data.t() | WardrikDaemon.Console.Table.t()
```

What one complete line renders to: styled text, or a table.

# `t`

```elixir
@type t() :: %WardrikDaemon.Console.Markdown{
  fenced?: boolean(),
  pending: String.t(),
  table: [String.t()]
}
```

Text not yet a complete line, whether it sits inside a fence, and the table rows held back.

# `code_blocks`

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

Returns the contents of each fenced code block in `text`, in order, without the fences or a trailing newline.

# `flush`

```elixir
@spec flush(t()) :: {[line()], t()}
```

Renders whatever is left, for the end of a stream.

# `line`

```elixir
@spec line(String.t()) :: Owl.Data.t()
```

Renders one complete line of markdown, outside any fence.

# `new`

```elixir
@spec new() :: t()
```

Returns an empty buffer.

# `push`

```elixir
@spec push(t(), String.t()) :: {[line()], t()}
```

Adds `text` and returns the lines it completed: rendered, in order, without their newlines.

# `tail`

```elixir
@spec tail(t()) :: Owl.Data.t() | nil
```

Returns the unfinished line, rendered as if the stream ended here, or `nil` if nothing is pending.

It's provisional: the same text is rendered again, as a line, once its newline arrives.

---

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