1- import { Fragment } from 'react' ;
2- import { jsx , jsxs } from 'react/jsx-runtime' ;
3- import { toJsxRuntime } from 'hast-util-to-jsx-runtime' ;
4- import { Nodes } from 'hastscript/lib/create-h' ;
5- import bash from 'refractor/lang/bash.js' ;
6- import json from 'refractor/lang/json.js' ;
7- import typescript from 'refractor/lang/typescript.js' ;
8- import { refractor } from 'refractor/lib/core.js' ;
9-
1+ import { getCurrentPlatform } from 'sentry-docs/docTree' ;
2+ import { serverContext } from 'sentry-docs/serverContext' ;
103import { PlatformCategory } from 'sentry-docs/types' ;
114
125import { Expandable } from './expandable' ;
6+ import { codeToJsx } from './highlightCode' ;
137import { RenderNestedObject } from './nestedObject' ;
148import { SdkDefinition } from './sdkDefinition' ;
159
@@ -35,32 +29,27 @@ type Props = {
3529 language ?: string ;
3630} ;
3731
38- refractor . register ( bash ) ;
39- refractor . register ( json ) ;
40- refractor . register ( typescript ) ;
41-
42- const codeToJsx = ( code : string , lang = 'json' ) => {
43- return toJsxRuntime ( refractor . highlight ( code , lang ) as Nodes , { Fragment, jsx, jsxs} ) ;
44- } ;
45-
4632export function SdkApi ( {
4733 name,
4834 children,
4935 signature,
5036 parameters = [ ] ,
51- // TODO: How to handle this default better?
52- language = 'typescript' ,
37+ language,
5338 categorySupported = [ ] ,
5439} : Props ) {
40+ const { rootNode, path} = serverContext ( ) ;
41+ const platform = getCurrentPlatform ( rootNode , path ) ;
42+ const lang = language || platform ?. language || 'typescript' ;
43+
5544 return (
5645 < SdkDefinition name = { name } categorySupported = { categorySupported } >
57- < pre className = "mt-2 mb-2 text-sm" > { codeToJsx ( signature , language ) } </ pre >
46+ < pre className = "mt-2 mb-2 text-sm" > { codeToJsx ( signature , lang ) } </ pre >
5847
5948 { parameters . length ? (
6049 < Expandable title = "Parameters" >
6150 < div className = "space-y-3" >
6251 { parameters . map ( param => (
63- < ApiParameterDef key = { param . name } language = { language } { ...param } />
52+ < ApiParameterDef key = { param . name } language = { lang } { ...param } />
6453 ) ) }
6554 </ div >
6655 </ Expandable >
0 commit comments