MingaEditor.Agent.MarkdownHighlight (Minga v0.1.0)

Copy Markdown View Source

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.

Summary

Types

A line of styled runs.

All styled lines for a message.

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

Functions

Converts assistant message text to styled runs for the GUI.

Types

styled_line()

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

A line of styled runs.

styled_lines()

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

All styled lines for a message.

styled_run()

@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}.

Functions

stylize(text, highlight, theme_syntax, buffer_byte_offset \\ 0)

@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.