UNPKG

ai-x-terminal

Version:

Enhance your command-line experience with AI capabilities using OpenAI's API. Easily integrate with projects and leverage AI in the terminal.

24 lines (23 loc) 735 B
import { highlight } from 'cli-highlight'; export const colorCode = (codeBlock) => { if (!codeBlock.includes(`\`\`\``)) return codeBlock; try { const chunkParts = codeBlock.split(`\`\`\``); const code = { language: chunkParts[1].split('\n')[0], content: chunkParts[1].split('\n').slice(1).join('\n'), }; const precode = chunkParts[0] + `\`\`\`` + code.language + '\n'; const postcode = `\`\`\`` + '\n' + chunkParts[2]; return (precode + highlight(code.content, { language: code.language, ignoreIllegals: true, }) + postcode); } catch { return codeBlock; } };