@@ -9,6 +9,18 @@ import jsonStringify from 'json-stringify-pretty-compact';
9
9
10
10
const BASE_PATH = 'docs' ;
11
11
12
+ type JsonExpressionSyntax = {
13
+ overloads : {
14
+ parameters : string [ ] ;
15
+ 'output-type' : string ;
16
+ } [ ] ;
17
+ parameters ?: {
18
+ name : string ;
19
+ type ?: string ;
20
+ description ?: string ;
21
+ } [ ] ;
22
+ }
23
+
12
24
type JsonSdkSupport = {
13
25
[ info : string ] : {
14
26
js ?: string ;
@@ -118,7 +130,32 @@ function sdkSupportToMarkdown(support: JsonSdkSupport): string {
118
130
markdown += `|${ row } |${ supportCell ( supportMatrix . js ) } |${ supportCell ( supportMatrix . android ) } |${ supportCell ( supportMatrix . ios ) } |\n` ;
119
131
}
120
132
return markdown ;
133
+ }
121
134
135
+ /**
136
+ * Converts the expression syntax object to markdown format.
137
+ * @param key - the expression name
138
+ * @param syntax - the expression syntax object in the style spec
139
+ * @returns the markdown string for the expression's syntax section
140
+ */
141
+ function expressionSyntaxToMarkdown ( key : string , syntax : JsonExpressionSyntax ) {
142
+ let markdown = '\nSyntax:\n' ;
143
+ const codeBlockLines = syntax . overloads . map ( ( overload ) => {
144
+ return `[${ [ `"${ key } "` , ...overload . parameters ] . join ( ', ' ) } ]: ${ overload [ 'output-type' ] } ` ;
145
+ } ) ;
146
+ markdown += `${ codeBlockMarkdown ( codeBlockLines . join ( '\n' ) , 'js' ) } \n` ;
147
+ for ( const parameter of syntax . parameters ?? [ ] ) {
148
+ markdown += `- \`${ parameter . name } \`` ;
149
+ if ( parameter . type ) {
150
+ const type = parameter . type . replaceAll ( '<' , '<' ) . replaceAll ( '>' , '>' ) ;
151
+ markdown += `: *${ type } *` ;
152
+ }
153
+ if ( parameter . description ) {
154
+ markdown += ` — ${ parameter . description } ` ;
155
+ }
156
+ markdown += '\n' ;
157
+ }
158
+ return markdown ;
122
159
}
123
160
124
161
/**
@@ -511,9 +548,8 @@ function createExpressionsContent() {
511
548
}
512
549
content += `\n### ${ key } \n` ;
513
550
content += `${ value . doc } \n` ;
514
- value . example . syntax . method . unshift ( `"${ key } "` ) ;
515
- content += `\nSyntax:\n${ codeBlockMarkdown ( `[${ value . example . syntax . method . join ( ', ' ) } ]: ${ value . example . syntax . result } ` , 'js' ) } \n` ;
516
- content += `\nExample:\n${ codeBlockMarkdown ( `"some-property": ${ formatJSON ( value . example . value ) } ` ) } \n` ;
551
+ content += expressionSyntaxToMarkdown ( key , value . syntax ) ;
552
+ content += `\nExample:\n${ codeBlockMarkdown ( `"some-property": ${ formatJSON ( value . example ) } ` ) } \n` ;
517
553
content += sdkSupportToMarkdown ( value [ 'sdk-support' ] as any ) ;
518
554
content += '\n' ;
519
555
}
0 commit comments