({
children,
lang,
isFencedBlock,
hideImports = true,
links,
styles
}: ICodeProps)
| 77 | } |
| 78 | |
| 79 | export function Code({ |
| 80 | children, |
| 81 | lang, |
| 82 | isFencedBlock, |
| 83 | hideImports = true, |
| 84 | links, |
| 85 | styles |
| 86 | }: ICodeProps) { |
| 87 | // If language is provided and is a supported syntax highlighting language |
| 88 | if (lang && isSupportedLanguage(lang)) { |
| 89 | return ( |
| 90 | <code className={styles} style={{fontFamily: 'inherit', WebkitTextSizeAdjust: 'none'}}> |
| 91 | <CodeClient tokens={highlightCode(children, lang, hideImports, links)} /> |
| 92 | </code> |
| 93 | ); |
| 94 | } |
| 95 | |
| 96 | if (lang === 'diff') { |
| 97 | return ( |
| 98 | <code className={styles} style={{fontFamily: 'inherit', WebkitTextSizeAdjust: 'none'}}> |
| 99 | {highlightDiff(children)} |
| 100 | </code> |
| 101 | ); |
| 102 | } |
| 103 | |
| 104 | // If inside a fenced code block (pre element) or has an unsupported language, |
| 105 | // render as plain text block without syntax highlighting |
| 106 | if (isFencedBlock || lang) { |
| 107 | return ( |
| 108 | <code className={styles} style={{fontFamily: 'inherit', WebkitTextSizeAdjust: 'none'}}> |
| 109 | {children} |
| 110 | </code> |
| 111 | ); |
| 112 | } |
| 113 | |
| 114 | // Inline code style |
| 115 | return ( |
| 116 | <code |
| 117 | className={style({ |
| 118 | font: 'code-sm', |
| 119 | color: { |
| 120 | default: 'code', |
| 121 | ':is(a>code)': 'inherit' |
| 122 | }, |
| 123 | backgroundColor: 'layer-1', |
| 124 | paddingX: 4, |
| 125 | borderWidth: 1, |
| 126 | borderColor: 'gray-100', |
| 127 | borderStyle: 'solid', |
| 128 | borderRadius: 'sm', |
| 129 | whiteSpace: 'pre-wrap' |
| 130 | })}> |
| 131 | {children} |
| 132 | </code> |
| 133 | ); |
| 134 | } |
| 135 | |
| 136 | const highlightCode = cache( |
nothing calls this directly
no test coverage detected