Skip to content

Commit f0bc192

Browse files
committed
fix: format array examples for typedoc
1 parent 71214e0 commit f0bc192

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

src/utils/jsdoc.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,20 @@ function processDescription(info: string): string {
1111
.replace(/<\/a>/g, '');
1212
}
1313

14+
function stringifyExample(example: unknown): string {
15+
const result = JSON.stringify(example, null, 2);
16+
if (Array.isArray(example)) {
17+
return '```\n' + result + '\n```';
18+
}
19+
return result;
20+
}
21+
1422
function exampleToString(example: unknown) {
1523
if (typeof example !== 'string') {
16-
return JSON.stringify(example, null, 4);
24+
return stringifyExample(example);
1725
}
1826
try {
19-
return JSON.stringify(JSON.parse(example), null, 2);
27+
return stringifyExample(JSON.parse(example));
2028
} catch (e) {
2129
return example;
2230
}
@@ -97,7 +105,11 @@ function renderJsDocTagAsPlainText(tag: JsDocBlockTag): string {
97105
if (tag.name === 'example') {
98106
const value = tag.value.replace(/[\n]?$/g, '\n');
99107
if (value.match(/^[\n]/)) {
100-
result += `:\n\`\`\`${value}\`\`\``;
108+
if (value.match(/^\n```/)) {
109+
result += `:\n${value}`;
110+
} else {
111+
result += `:\n\`\`\`${value}\`\`\``;
112+
}
101113
} else {
102114
result += `:${value.replace(/^([^\n]+)\n/, ' "$1":\n```')}\`\`\``;
103115
}

0 commit comments

Comments
 (0)