# `MingaAgent.Markdown`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_agent/markdown.ex#L1)

Simple markdown parser for agent chat rendering.

Parses a subset of markdown into styled line segments suitable for
terminal rendering. This is intentionally not a full CommonMark parser;
it handles the patterns that LLM output commonly uses.

## Supported syntax

- `**bold**` and `__bold__`
- `*italic*` and `_italic_`
- `` `inline code` ``
- Fenced code blocks (``` with optional language tag)
- `# Headers` (levels 1-3)
- `- list items` and `* list items`
- `> blockquotes`
- Horizontal rules (`---`, `***`, `___`)

## Output format

Returns a list of `{line_segments, line_type}` tuples where each
`line_segments` is a list of `{text, style}` pairs and `line_type`
indicates the block context.

# `code_block`

```elixir
@type code_block() :: %{language: String.t(), content: String.t()}
```

Extracted code block with language and content.

# `line_type`

```elixir
@type line_type() ::
  :text
  | :code
  | {:code_header, String.t()}
  | :header
  | :blockquote
  | :list_item
  | :rule
  | :empty
```

Line type indicating block context.

# `parsed_line`

```elixir
@type parsed_line() :: {[segment()], line_type()}
```

A parsed line with its segments and type.

# `segment`

```elixir
@type segment() :: {String.t(), style()}
```

A styled text segment.

# `style`

```elixir
@type style() ::
  :plain
  | :bold
  | :italic
  | :bold_italic
  | :code
  | :code_block
  | {:code_content, String.t()}
  | :header1
  | :header2
  | :header3
  | :blockquote
  | :list_bullet
  | :rule
```

Style attributes for a text segment.

# `extract_code_blocks`

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

Extracts fenced code blocks from markdown text.

Returns a list of `%{language: String.t(), content: String.t()}` maps,
one per fenced code block. The content excludes the fence markers.

# `parse`

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

Parses markdown text into styled line segments.

Returns a list of `{segments, line_type}` tuples, one per output line.

# `parse_inline`

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

Parses inline markdown formatting within a single line.

Returns a list of `{text, style}` segments.

---

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