markdowntransform

package
v0.5.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 22, 2026 License: MIT Imports: 1 Imported by: 0

Documentation

Overview

Package markdowntransform holds the display-only Markdown transformer contract and its chain. It is a dependency-free leaf, so both the extension API (which re-exports these types) and the tui message components that take transformers share one definition.

Ports packages/coding-agent/src/modes/interactive/components/markdown-transform.ts

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ApplyMarkdownTransformers

func ApplyMarkdownTransformers(markdown string, ctx MarkdownTransformContext, transformers []MarkdownTransformer) string

ApplyMarkdownTransformers runs transformers in order on markdown. A transformer that panics keeps the current Markdown, and a done ctx.Context stops the chain with the Markdown transformed so far.

func CreateMarkdownTransform

func CreateMarkdownTransform(messageType MarkdownMessageType, isStreaming bool, transformers []MarkdownTransformer) func(markdown string, availableWidth int) string

CreateMarkdownTransform returns the transform a Markdown component applies at its available width: each transformer rewrites the Markdown in turn, and one that panics is skipped with the current Markdown kept. It is Pi's createMarkdownTransform(messageType, isStreaming, transformers).

Types

type MarkdownMessageType

type MarkdownMessageType string

MarkdownMessageType identifies the transcript message being transformed for display. Transformers never change model context or persisted message data.

const (
	MarkdownMessageUser      MarkdownMessageType = "user"
	MarkdownMessageAssistant MarkdownMessageType = "assistant"
	// MarkdownMessageAssistantThinking marks the reasoning/thinking trace of an assistant turn. Mirrors upstream
	// MarkdownTransformContext.messageType "assistant-thinking"; the built-in Mermaid transformer skips it.
	MarkdownMessageAssistantThinking MarkdownMessageType = "assistant-thinking"
)

type MarkdownTransformContext

type MarkdownTransformContext struct {
	// Context owns the off-loop host generation; it is not part of Pi's wire context.
	Context context.Context `json:"-"`
	// Retry is nil where nothing re-renders a message; otherwise a host proxy calls its RequestRetry, off the UI loop, once an abandoned transform can be asked again (D56). It is not part of Pi's wire context.
	Retry          RetryRequester      `json:"-"`
	MessageType    MarkdownMessageType `json:"messageType"`
	IsStreaming    bool                `json:"isStreaming"`
	AvailableWidth int                 `json:"availableWidth"`
}

MarkdownTransformContext mirrors upstream MarkdownTransformContext.

type MarkdownTransformer

type MarkdownTransformer func(markdown string, context MarkdownTransformContext) string

MarkdownTransformer performs a synchronous display-only Markdown rewrite.

type RetryRequester

type RetryRequester interface{ RequestRetry() }

RetryRequester marks the message being transformed as changed, so its next frame transforms it again.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL