@@ -9,6 +9,18 @@ import jsonStringify from 'json-stringify-pretty-compact';
99
1010const BASE_PATH = 'docs' ;
1111
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+
1224type JsonSdkSupport = {
1325 [ info : string ] : {
1426 js ?: string ;
@@ -118,7 +130,32 @@ function sdkSupportToMarkdown(support: JsonSdkSupport): string {
118130 markdown += `|${ row } |${ supportCell ( supportMatrix . js ) } |${ supportCell ( supportMatrix . android ) } |${ supportCell ( supportMatrix . ios ) } |\n` ;
119131 }
120132 return markdown ;
133+ }
121134
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 ;
122159}
123160
124161/**
@@ -511,9 +548,8 @@ function createExpressionsContent() {
511548 }
512549 content += `\n### ${ key } \n` ;
513550 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` ;
517553 content += sdkSupportToMarkdown ( value [ 'sdk-support' ] as any ) ;
518554 content += '\n' ;
519555 }
0 commit comments