@@ -32,6 +32,10 @@ type Props = {
3232 api : API ;
3333} ;
3434
35+ const codeToJsx = ( code : string , lang = 'json' ) => {
36+ return toJsxRuntime ( refractor . highlight ( code , lang ) as Nodes , { Fragment, jsx, jsxs} ) ;
37+ } ;
38+
3539export function ApiExamples ( { api} : Props ) {
3640 const apiExample = [
3741 `curl https://sentry.io${ api . apiPath } ` ,
@@ -96,16 +100,7 @@ export function ApiExamples({api}: Props) {
96100 < Fragment >
97101 < CodeTabs >
98102 < CodeBlock language = "bash" >
99- < pre >
100- { toJsxRuntime (
101- refractor . highlight ( apiExample . join ( ' \\\n' ) , 'bash' ) as Nodes ,
102- {
103- Fragment,
104- jsx,
105- jsxs,
106- }
107- ) }
108- </ pre >
103+ < pre > { codeToJsx ( apiExample . join ( ' \\\n' ) , 'bash' ) } </ pre >
109104 </ CodeBlock >
110105 </ CodeTabs >
111106 < div className = "api-block" >
@@ -152,29 +147,16 @@ export function ApiExamples({api}: Props) {
152147 { selectedTabView === 0 &&
153148 ( exampleJson ? (
154149 < code className = "!text-[0.8rem]" >
155- { toJsxRuntime (
156- refractor . highlight (
157- JSON . stringify ( exampleJson , null , 2 ) ,
158- 'json'
159- ) as Nodes ,
160- { Fragment, jsx, jsxs}
161- ) }
150+ { codeToJsx ( JSON . stringify ( exampleJson , null , 2 ) , 'json' ) }
162151 </ code >
163152 ) : (
164153 strFormat ( api . responses [ selectedResponse ] . description )
165154 ) ) }
166155 { selectedTabView === 1 && (
167156 < code className = "!text-[0.8rem]" >
168- { toJsxRuntime (
169- refractor . highlight (
170- JSON . stringify (
171- api . responses [ selectedResponse ] . content ?. schema ,
172- null ,
173- 2
174- ) ,
175- 'json'
176- ) as Nodes ,
177- { Fragment, jsx, jsxs}
157+ { codeToJsx (
158+ JSON . stringify ( api . responses [ selectedResponse ] . content ?. schema , null , 2 ) ,
159+ 'json'
178160 ) }
179161 </ code >
180162 ) }
0 commit comments