# `MingaEditor.Agent.MarkdownHighlight`
[🔗](https://github.com/jsmestad/minga/blob/main/lib/minga_editor/agent/markdown_highlight.ex#L1)

Converts agent assistant messages to styled text runs for the GUI.

Uses a hybrid approach:
- **Regex-based Markdown parser** for structure (headers, bold, italic,
  inline code, lists, blockquotes, rules). This strips syntax markers
  so the GUI shows clean rendered text, not raw `**` or `##`.
- **Tree-sitter highlights** overlaid on fenced code block content. This
  gives per-language syntax highlighting (Elixir, Python, etc.) inside
  code blocks, which the regex parser can't do.

The regex path always runs. Tree-sitter is layered on top for code
blocks only when highlight spans are available.

# `styled_line`

```elixir
@type styled_line() :: [styled_run()]
```

A line of styled runs.

# `styled_lines`

```elixir
@type styled_lines() :: [styled_line()]
```

All styled lines for a message.

# `styled_run`

```elixir
@type styled_run() ::
  {String.t(), non_neg_integer(), non_neg_integer(), non_neg_integer()}
```

A single styled text run: {text, fg_rgb, bg_rgb, flags}.

# `stylize`

```elixir
@spec stylize(
  String.t(),
  MingaEditor.UI.Highlight.t() | nil,
  map(),
  non_neg_integer()
) ::
  styled_lines()
```

Converts assistant message text to styled runs for the GUI.

Always uses the regex-based Markdown parser for structure (strips
syntax markers). When tree-sitter highlights are available, overlays
per-language syntax highlighting onto fenced code block content lines.

`buffer_byte_offset` is the starting byte offset of this message's
text within the full `*Agent*` buffer. Required for aligning
tree-sitter spans (which reference the full buffer) with per-message
line content.

---

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