/** * [WHO]: DefaultTextStyle, MarkdownTheme, Markdown * [FROM]: Depends on marked, ../terminal-image.js, ../utils.js * [TO]: Consumed by core/lib/tui/src/index.ts * [HERE]: core/lib/tui/src/components/markdown.ts - */ import type { Component } from "../tui.js"; /** * Default text styling for markdown content. * Applied to all text unless overridden by markdown formatting. */ export interface DefaultTextStyle { /** Foreground color function */ color?: (text: string) => string; /** Background color function */ bgColor?: (text: string) => string; /** Bold text */ bold?: boolean; /** Italic text */ italic?: boolean; /** Strikethrough text */ strikethrough?: boolean; /** Underline text */ underline?: boolean; } /** * Theme functions for markdown elements. * Each function takes text and returns styled text with ANSI codes. */ export interface MarkdownTheme { heading: (text: string) => string; link: (text: string) => string; linkUrl: (text: string) => string; code: (text: string) => string; codeBlock: (text: string) => string; codeBlockBorder: (text: string) => string; quote: (text: string) => string; quoteBorder: (text: string) => string; hr: (text: string) => string; listBullet: (text: string) => string; bold: (text: string) => string; italic: (text: string) => string; strikethrough: (text: string) => string; underline: (text: string) => string; highlightCode?: (code: string, lang?: string) => string[]; /** Prefix applied to each rendered code block line (default: " ") */ codeBlockIndent?: string; } export declare class Markdown implements Component { private text; private paddingX; private paddingY; private defaultTextStyle?; private theme; private defaultStylePrefix?; private cachedText?; private cachedWidth?; private cachedLines?; constructor(text: string, paddingX: number, paddingY: number, theme: MarkdownTheme, defaultTextStyle?: DefaultTextStyle); setText(text: string): void; invalidate(): void; render(width: number): string[]; /** * Apply default text style to a string. * This is the base styling applied to all text content. * NOTE: Background color is NOT applied here - it's applied at the padding stage * to ensure it extends to the full line width. */ private applyDefaultStyle; private getDefaultStylePrefix; private getStylePrefix; private getDefaultInlineStyleContext; private renderToken; private renderInlineTokens; /** * Render a list with proper nesting support */ private renderList; /** * Render list item tokens, handling nested lists * Returns lines WITHOUT the parent indent (renderList will add it) */ private renderListItem; /** * Get the visible width of the longest word in a string. */ private getLongestWordWidth; /** * Wrap a table cell to fit into a column. * * Delegates to wrapTextWithAnsi() so ANSI codes + long tokens are handled * consistently with the rest of the renderer. */ private wrapCellText; /** * Render a table with width-aware cell wrapping. * Cells that don't fit are wrapped to multiple lines. */ private renderTable; }