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} or {text, fg_rgb, bg_rgb, flags, url}.

Functions

Converts assistant message text to semantic markdown blocks for GUI code-card rendering.

Converts assistant message text to styled runs for the GUI.

Types

highlighter()

@type highlighter() :: (String.t(), String.t(), keyword() -> highlighter_result())

highlighter_result()

@type highlighter_result() ::
  {:ok, [String.t()], [Minga.Language.Highlight.Span.t()]}
  | :unsupported
  | :timeout
  | :unavailable
  | {:error, term()}
  | nil

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()

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

Functions

render_blocks(text, highlight, theme_syntax, message_id, buffer_byte_offset \\ 0, opts \\ [])

Converts assistant message text to semantic markdown blocks for GUI code-card rendering.

Inline code remains a styled-run flag inside paragraph/list/heading runs. Fenced code becomes an explicit MarkdownBlock code block; frontends should render cards from this block kind, not from 0x10.

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 transcript markdown used for highlighting. Required for aligning tree-sitter spans with per-message line content.