@@ -4,7 +4,7 @@ import React, { useEffect, useMemo, useState } from 'react'
44import { Check , Copy } from 'lucide-react'
55import ReactMarkdown from 'react-markdown'
66import remarkGfm from 'remark-gfm'
7- import { Tooltip } from '@/components/emcn'
7+ import { Code , Tooltip } from '@/components/emcn'
88
99/**
1010 * Recursively extracts text content from React elements
@@ -28,56 +28,30 @@ const getTextContent = (element: React.ReactNode): string => {
2828 return ''
2929}
3030
31- // Fix for code block text rendering issues
31+ // Global layout fixes for markdown content inside the copilot panel
3232if ( typeof document !== 'undefined' ) {
3333 const styleId = 'copilot-markdown-fix'
3434 if ( ! document . getElementById ( styleId ) ) {
3535 const style = document . createElement ( 'style' )
3636 style . id = styleId
3737 style . textContent = `
38- .copilot-markdown-wrapper pre {
39- color: #F5F5F5 !important;
40- font-weight: 400 !important;
41- text-shadow: none !important;
42- filter: none !important;
43- opacity: 1 !important;
44- -webkit-font-smoothing: antialiased !important;
45- -moz-osx-font-smoothing: grayscale !important;
46- text-rendering: optimizeLegibility !important;
47- max-width: 100% !important;
48- overflow: auto !important;
49- }
50-
51- .dark .copilot-markdown-wrapper pre {
52- color: #F0F0F0 !important;
53- }
54-
55- .copilot-markdown-wrapper pre code,
56- .copilot-markdown-wrapper pre code *,
57- .copilot-markdown-wrapper pre span,
58- .copilot-markdown-wrapper pre div {
59- color: inherit !important;
60- opacity: 1 !important;
61- font-weight: 400 !important;
62- text-shadow: none !important;
63- filter: none !important;
64- -webkit-font-smoothing: antialiased !important;
65- -moz-osx-font-smoothing: grayscale !important;
66- text-rendering: optimizeLegibility !important;
67- }
68-
6938 /* Prevent any markdown content from expanding beyond the panel */
70- .copilot-markdown-wrapper, .copilot-markdown-wrapper * {
39+ .copilot-markdown-wrapper,
40+ .copilot-markdown-wrapper * {
7141 max-width: 100% !important;
7242 }
73- .copilot-markdown-wrapper p, .copilot-markdown-wrapper li {
43+
44+ .copilot-markdown-wrapper p,
45+ .copilot-markdown-wrapper li {
7446 overflow-wrap: anywhere !important;
7547 word-break: break-word !important;
7648 }
49+
7750 .copilot-markdown-wrapper a {
7851 overflow-wrap: anywhere !important;
7952 word-break: break-all !important;
8053 }
54+
8155 .copilot-markdown-wrapper code:not(pre code) {
8256 white-space: normal !important;
8357 overflow-wrap: anywhere !important;
@@ -219,7 +193,7 @@ export default function CopilotMarkdownRenderer({ content }: CopilotMarkdownRend
219193 </ li >
220194 ) ,
221195
222- // Code blocks
196+ // Code blocks - render using shared Code.Viewer for consistent styling
223197 pre : ( { children } : React . HTMLAttributes < HTMLPreElement > ) => {
224198 let codeContent : React . ReactNode = children
225199 let language = 'code'
@@ -272,13 +246,24 @@ export default function CopilotMarkdownRenderer({ content }: CopilotMarkdownRend
272246 }
273247 }
274248
249+ // Map markdown language tag to Code.Viewer supported languages
250+ const normalizedLanguage = ( language || '' ) . toLowerCase ( )
251+ const viewerLanguage : 'javascript' | 'json' | 'python' =
252+ normalizedLanguage === 'json'
253+ ? 'json'
254+ : normalizedLanguage === 'python' || normalizedLanguage === 'py'
255+ ? 'python'
256+ : 'javascript'
257+
275258 return (
276- < div className = 'my-6 w-0 min-w-full rounded-md bg-gray-900 text-sm dark:bg-black' >
277- < div className = 'flex items-center justify-between border-gray-700 border-b px-4 py-1.5 dark:border-gray-800' >
278- < span className = 'font-season text-gray-400 text-xs' > { language } </ span >
259+ < div className = 'my-6 w-0 min-w-full overflow-hidden rounded-md border border-[var(--border-strong)] bg-[#1F1F1F] text-sm' >
260+ < div className = 'flex items-center justify-between border-[var(--border-strong)] border-b px-4 py-1.5' >
261+ < span className = 'font-season text-[#A3A3A3] text-xs' >
262+ { language === 'code' ? viewerLanguage : language }
263+ </ span >
279264 < button
280265 onClick = { handleCopy }
281- className = 'text-muted-foreground transition-colors hover:text-gray-300'
266+ className = 'text-[#A3A3A3] transition-colors hover:text-gray-300'
282267 title = 'Copy'
283268 >
284269 { showCopySuccess ? (
@@ -288,11 +273,12 @@ export default function CopilotMarkdownRenderer({ content }: CopilotMarkdownRend
288273 ) }
289274 </ button >
290275 </ div >
291- < div className = 'overflow-x-auto' >
292- < pre className = 'whitespace-pre p-4 font-mono text-[#F5F5F5] text-sm leading-relaxed dark:text-[#F0F0F0]' >
293- { actualCodeText }
294- </ pre >
295- </ div >
276+ < Code . Viewer
277+ code = { actualCodeText }
278+ showGutter
279+ language = { viewerLanguage }
280+ className = 'm-0 rounded-none border-0 bg-transparent'
281+ />
296282 </ div >
297283 )
298284 } ,
@@ -307,7 +293,7 @@ export default function CopilotMarkdownRenderer({ content }: CopilotMarkdownRend
307293 if ( inline ) {
308294 return (
309295 < code
310- className = 'whitespace-normal break-all rounded bg-gray-300 px-1 py-0.5 font-mono text-[#707070 ] text-[0.9em] dark:bg-[var(--surface-11)] dark:text-[#E8E8E8 ]'
296+ className = 'whitespace-normal break-all rounded border border-[var(--border-strong)] bg-[#1F1F1F] px-1 py-0.5 font-mono text-[#eeeeee ] text-[0.9em]'
311297 { ...props }
312298 >
313299 { children }
0 commit comments