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' ;
10
3
import { PlatformCategory } from 'sentry-docs/types' ;
11
4
12
5
import { Expandable } from './expandable' ;
6
+ import { codeToJsx } from './highlightCode' ;
13
7
import { RenderNestedObject } from './nestedObject' ;
14
8
import { SdkDefinition } from './sdkDefinition' ;
15
9
@@ -35,32 +29,27 @@ type Props = {
35
29
language ?: string ;
36
30
} ;
37
31
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
-
46
32
export function SdkApi ( {
47
33
name,
48
34
children,
49
35
signature,
50
36
parameters = [ ] ,
51
- // TODO: How to handle this default better?
52
- language = 'typescript' ,
37
+ language,
53
38
categorySupported = [ ] ,
54
39
} : Props ) {
40
+ const { rootNode, path} = serverContext ( ) ;
41
+ const platform = getCurrentPlatform ( rootNode , path ) ;
42
+ const lang = language || platform ?. language || 'typescript' ;
43
+
55
44
return (
56
45
< 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 >
58
47
59
48
{ parameters . length ? (
60
49
< Expandable title = "Parameters" >
61
50
< div className = "space-y-3" >
62
51
{ parameters . map ( param => (
63
- < ApiParameterDef key = { param . name } language = { language } { ...param } />
52
+ < ApiParameterDef key = { param . name } language = { lang } { ...param } />
64
53
) ) }
65
54
</ div >
66
55
</ Expandable >
0 commit comments