MCPcopy Create free account
hub / github.com/adobe/react-spectrum / Code

Function Code

packages/dev/s2-docs/src/Code.tsx:79–134  ·  view source on GitHub ↗
({
  children,
  lang,
  isFencedBlock,
  hideImports = true,
  links,
  styles
}: ICodeProps)

Source from the content-addressed store, hash-verified

77}
78
79export 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
136const highlightCode = cache(

Callers

nothing calls this directly

Calls 2

isSupportedLanguageFunction · 0.85
highlightDiffFunction · 0.85

Tested by

no test coverage detected