(options?: { transient?: boolean })
| 23 | const HEADING_HASH_PREFIX = /^((?:\u001B\[[0-9;]*m)*)#{1,6}[ \t]+/; |
| 24 | |
| 25 | export function createMarkdownTheme(options?: { transient?: boolean }): MarkdownTheme { |
| 26 | const transient = options?.transient === true; |
| 27 | const stripHash = (text: string): string => text.replace(HEADING_HASH_PREFIX, '$1'); |
| 28 | |
| 29 | return { |
| 30 | heading: (text) => chalk.bold.hex(currentTheme.color('text'))(stripHash(text)), |
| 31 | link: (text) => chalk.hex(currentTheme.color('primary'))(text), |
| 32 | linkUrl: (text) => chalk.hex(currentTheme.color('textMuted'))(text), |
| 33 | code: (text) => chalk.hex(currentTheme.color('primary'))(text), |
| 34 | codeBlock: (text) => text, |
| 35 | codeBlockBorder: (text) => chalk.hex(currentTheme.color('textMuted'))(text), |
| 36 | quote: (text) => chalk.hex(currentTheme.color('textDim'))(text), |
| 37 | quoteBorder: (text) => chalk.hex(currentTheme.color('textDim'))(text), |
| 38 | hr: (text) => chalk.hex(currentTheme.color('border'))(text), |
| 39 | // Match the assistant-message bullet so list markers read like a reply |
| 40 | // prefix. Ordered lists arrive as "1. " / "2. " and are left |
| 41 | // untouched by the leading-dash anchor. |
| 42 | listBullet: (text) => chalk.hex(currentTheme.color('text'))(text.replace(/^-/, '•')), |
| 43 | bold: (text) => chalk.bold(text), |
| 44 | italic: (text) => chalk.italic(text), |
| 45 | strikethrough: (text) => chalk.strikethrough(text), |
| 46 | underline: (text) => chalk.underline(text), |
| 47 | highlightCode: (code: string, lang?: string) => { |
| 48 | if (transient) return code.split('\n'); |
| 49 | |
| 50 | const normalizedLang = lang?.trim().toLowerCase(); |
| 51 | const language = |
| 52 | normalizedLang !== undefined && supportsLanguage(normalizedLang) ? normalizedLang : 'text'; |
| 53 | try { |
| 54 | const highlighted = highlight(code, { language, ignoreIllegals: true }); |
| 55 | return highlighted.split('\n'); |
| 56 | } catch { |
| 57 | return code.split('\n'); |
| 58 | } |
| 59 | }, |
| 60 | }; |
| 61 | } |
| 62 | |
| 63 | export function createEditorTheme(): EditorTheme { |
| 64 | return { |
no test coverage detected