MCPcopy Create free account
hub / github.com/Noumena-Network/code / FencedCode

Function FencedCode

src/components/Markdown/FencedCode.tsx:23–63  ·  view source on GitHub ↗
({
  code,
  language,
  getFallbackAnsi,
  terminalWidth,
  dimColor,
}: Props)

Source from the content-addressed store, hash-verified

21 * while no native renderer exists it preserves the current <Ansi> behavior.
22 */
23export function FencedCode({
24 code,
25 language,
26 getFallbackAnsi,
27 terminalWidth,
28 dimColor,
29}: Props): React.ReactNode {
30 const hasUsableTerminalWidth =
31 Number.isFinite(terminalWidth) && terminalWidth > 0
32 const nativeLines =
33 dimColor || !hasUsableTerminalWidth
34 ? null
35 : renderNativeFence({
36 code,
37 language,
38 terminalWidth,
39 })
40
41 if (nativeLines) {
42 recordNativeFencedCodeRender({
43 language,
44 terminalWidth,
45 codeLength: code.length,
46 nativeLineCount: nativeLines.length,
47 })
48 return <RawAnsi lines={nativeLines as string[]} width={terminalWidth} />
49 }
50
51 const fallbackAnsi = getFallbackAnsi()
52 recordFencedCodeAnsiFallback({
53 language,
54 terminalWidth,
55 codeLength: code.length,
56 reason: dimColor
57 ? 'dim-color'
58 : !hasUsableTerminalWidth
59 ? 'no-terminal-width'
60 : 'native-unavailable',
61 })
62 return <Ansi dimColor={dimColor}>{fallbackAnsi}</Ansi>
63}

Callers 1

Calls 3

renderNativeFenceFunction · 0.85

Tested by

no test coverage detected