Skip to content

Commit 7d9a345

Browse files
committed
fix: format plain jsdoc with tsdoc compatibility
1 parent cbf4e04 commit 7d9a345

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/utils/jsdoc.ts

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,28 @@ export function renderJsDocList(items: string[]): string {
9090
return items.map((item) => ` * ${item.trim().replace(/\n/g, '\n ')}`).join('\n\n');
9191
}
9292

93+
function renderJsDocTagAsPlainText(tag: JsDocBlockTag): string {
94+
let result = `${tag.name}`;
95+
96+
if (tag.value) {
97+
if (tag.name === 'example') {
98+
if (tag.value.match(/^[\n\r \t]/)) {
99+
result += `:${tag.value}`;
100+
} else {
101+
result += `:${tag.value.replace(/^([^\n]+)\n/, ' "$1":\n```')}\`\`\``;
102+
}
103+
} else {
104+
result += ':';
105+
if (!tag.value.match(/^[\n\r \t]/)) {
106+
result += ' ';
107+
}
108+
result += tag.value;
109+
}
110+
}
111+
112+
return result;
113+
}
114+
93115
export function renderJsDocAsPlainText(jsdoc: JsDocBlock): string | null {
94116
const bits: string[] = [];
95117
const title = jsdoc.title && jsdoc.title.trim();
@@ -101,7 +123,7 @@ export function renderJsDocAsPlainText(jsdoc: JsDocBlock): string | null {
101123
bits.push(description);
102124
}
103125
if (jsdoc.tags.length > 0) {
104-
bits.push(jsdoc.tags.map(({name, value}) => `${name}${value ? `: ${value.trim()}` : ''}`).join('\n'));
126+
bits.push(jsdoc.tags.map(renderJsDocTagAsPlainText).join('\n'));
105127
}
106128
if (bits.length === 0) {
107129
return null;

0 commit comments

Comments
 (0)