Skip to content

Commit 1ef6397

Browse files
move to different functions for better readability
1 parent 26e80de commit 1ef6397

File tree

1 file changed

+55
-31
lines changed

1 file changed

+55
-31
lines changed

build/generate-docs.ts

Lines changed: 55 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -195,53 +195,77 @@ function expressionSyntaxToMarkdown(key: string, syntax: JsonExpressionSyntax) {
195195
});
196196
markdown += `${codeBlockMarkdown(codeBlockLines.join('\n'), 'js')}\n`;
197197
for (const parameter of syntax.parameters ?? []) {
198-
const type = parameterTypeToType(parameter.type)
199-
.replaceAll('<', '&lt;')
200-
.replaceAll('>', '&gt;');
198+
const type = parameterTypeToType(parameter.type);
201199
markdown += `- \`${parameter.name}\`: \`${type}\``;
202200
if (parameter.doc) {
203201
markdown += `- ${parameter.doc}`;
204202
}
205203
if (typeof parameter.type !== 'string' && !Array.isArray(parameter.type)) {
206204
// the type is an object type => we can attach more documentation about the contained variables
207205
markdown += ' \nParameters:';
208-
Object.entries(parameter.type).forEach(([key, val]) => {
209-
const type = jsonObjectToType(val).replaceAll('<', '&lt;').replaceAll('>', '&gt;');
210-
markdown += `\n - \`${key}\`: \`${type}\` - ${val.doc}`;
211-
if (val.type === 'enum' && val.values) {
212-
markdown += ' \n Possible values are:';
213-
for (const [enumKey, enumValue] of Object.entries(val.values)) {
214-
const defaultIndicator = val.default === enumKey ? ' *default*' : '';
215-
markdown += `\n - \`"${enumKey}"\`${defaultIndicator} - ${enumValue.doc}`;
216-
}
217-
}
218-
});
206+
const containedVariables = containedVariablesToMarkdown(parameter.type);
207+
for (const line of containedVariables.split('\n')) {
208+
markdown += `\n ${line}`;
209+
}
219210
}
220211
if (parameter.type === 'interpolation') {
221-
// the type is a non-basic type => we can attach further docs from v8
222-
const interpolation = v8.interpolation;
223-
markdown += ` \n ${interpolation.doc}`;
224-
const interpolation_name=v8.interpolation_name;
225-
markdown += ` \n Possible values are:`;
226-
for (const [key,val] of Object.entries(interpolation_name.values)) {
227-
markdown += ` \n - \`["${key}"`
228-
for (const param of val.syntax.overloads[0].parameters) {
229-
markdown += `, ${param}`
230-
}
231-
markdown += `]\`: ${val.doc}`;
232-
if (val.syntax.parameters.length) {
233-
markdown += ` \n Parameters are:`
234-
for (const param of val.syntax.parameters) {
235-
markdown += `\n - \`${param.name}\`: ${param.doc}`
236-
}
237-
}
212+
markdown += " ";
213+
const interpolationSyntax = interpolationSyntaxToMarkdown();
214+
for (const line of interpolationSyntax.split('\n')) {
215+
markdown += `\n ${line}`;
238216
}
239217
}
240218
markdown += '\n';
241219
}
242220
return markdown;
243221
}
244222

223+
/**
224+
* Converts the contained variables object to markdown format.
225+
* @param type - the contained variables object
226+
* @returns the markdown string for the interpolation's syntax section
227+
*/
228+
function containedVariablesToMarkdown(type: {[key: string]: JsonObject}) {
229+
let markdown = "";
230+
Object.entries(type).forEach(([key, val]) => {
231+
const type = jsonObjectToType(val);
232+
markdown += `\n- \`${key}\`: \`${type}\` - ${val.doc}`;
233+
if (val.type === 'enum' && val.values) {
234+
markdown += ' \n Possible values are:';
235+
for (const [enumKey, enumValue] of Object.entries(val.values)) {
236+
const defaultIndicator = val.default === enumKey ? ' *default*' : '';
237+
markdown += `\n - \`"${enumKey}"\`${defaultIndicator} - ${enumValue.doc}`;
238+
}
239+
}
240+
});
241+
return markdown
242+
}
243+
244+
/**
245+
* Converts the interpolation syntax object to markdown format.
246+
* @returns the markdown string for the interpolation's syntax section
247+
*/
248+
function interpolationSyntaxToMarkdown() {
249+
const interpolation = v8.interpolation;
250+
let markdown = interpolation.doc;
251+
const interpolation_name=v8.interpolation_name;
252+
markdown += ` \nPossible values are:`;
253+
for (const [key,val] of Object.entries(interpolation_name.values)) {
254+
markdown += ` \n - \`["${key}"`
255+
for (const param of val.syntax.overloads[0].parameters) {
256+
markdown += `, ${param}`
257+
}
258+
markdown += `]\`: ${val.doc}`;
259+
if (val.syntax.parameters.length) {
260+
markdown += ` \n Parameters are:`
261+
for (const param of val.syntax.parameters) {
262+
markdown += ` \n \`${param.name}\`: ${param.doc}`
263+
}
264+
}
265+
}
266+
return markdown
267+
}
268+
245269
/**
246270
* The requires field has some syntax which can contain "!" and "source".
247271
* @param requires - a list of requirements for the property

0 commit comments

Comments
 (0)