File tree Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Expand file tree Collapse file tree 1 file changed +15
-3
lines changed Original file line number Diff line number Diff 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+
1422function 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 }
You can’t perform that action at this time.
0 commit comments