diff --git a/desktop/src/components/markdown/MarkdownRenderer.tsx b/desktop/src/components/markdown/MarkdownRenderer.tsx index bd10e9f7..a0d2eb1d 100644 --- a/desktop/src/components/markdown/MarkdownRenderer.tsx +++ b/desktop/src/components/markdown/MarkdownRenderer.tsx @@ -1,54 +1,25 @@ -import { useMemo } from 'react' +import { useMemo, useCallback } from 'react' import { marked, type Tokens } from 'marked' -import { escapeHtml, highlightCodeLines, isHighlightable } from '../chat/highlightCode' +import { CodeViewer } from '../chat/CodeViewer' type Props = { content: string } +type CodeBlock = { + id: string + code: string + language: string | undefined +} + const renderer = new marked.Renderer() +let pendingCodeBlocks: CodeBlock[] = [] + renderer.code = function ({ text, lang }: Tokens.Code) { - const languageLabel = escapeHtml(lang || 'code') - const lines = text.split('\n') - const hasLanguage = isHighlightable(lang) - const highlightedLines = highlightCodeLines(text, lang) - - // Show line numbers only when language is known (actual code). - // Plain text, file trees, command output etc. look better without them. - const body = hasLanguage - ? highlightedLines - .map((line, index) => ` -