Skip to content

Commit 5886815

Browse files
feat: render jsDocs and source url for classes and interfaces (#68)
* feat: render jsDocs for classes and interfaces * 🤖 Documentation auto-update * feat: print references in class * feat: interfaces links and markdown * test: see --------- Co-authored-by: github-actions <41898282+github-actions[bot]@users.noreply.github.com>
1 parent 589c01a commit 5886815

File tree

5 files changed

+60
-16
lines changed

5 files changed

+60
-16
lines changed

src/lib/parser/markdown.ts

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
MarkdownOptions
88
} from '../types';
99
import {jsDocsMetadata, jsDocsToParams} from './jdocs/mapper';
10-
import {emojiTitle, metadataToMarkdown, sourceCodeLink} from './render';
10+
import {emojiTitle, metadataToMarkdown} from './render';
1111
import type {Params, Row} from './types';
1212

1313
const toParams = (parameters?: DocEntry[]): Params[] =>
@@ -39,17 +39,21 @@ const classesToMarkdown = ({
3939
entry: DocEntry;
4040
} & Required<Pick<MarkdownOptions, 'headingLevel'>> &
4141
Omit<MarkdownOptions, 'headingLevel'>): string => {
42-
const {name, url, documentation, methods, properties, constructors} = entry;
42+
const {name, url, documentation, methods, properties, constructors, jsDocs} = entry;
4343

4444
const markdown: string[] = [`${headingLevel}${emojiTitle({emoji, key: 'classes'})} ${name}\n`];
4545

4646
if (documentation !== undefined && documentation !== '') {
4747
markdown.push(`${documentation}\n`);
4848
}
4949

50-
if (url !== undefined) {
51-
markdown.push(sourceCodeLink({emoji, url}));
52-
}
50+
const metadata = metadataToMarkdown({
51+
...jsDocsMetadata(jsDocs),
52+
url,
53+
emoji
54+
});
55+
56+
markdown.push(...metadata);
5357

5458
const publicConstructors: DocEntryConstructor[] = (constructors ?? []).filter(
5559
({visibility}) => visibility === 'public'
@@ -146,7 +150,7 @@ const interfacesToMarkdown = ({
146150
} & Required<Pick<MarkdownOptions, 'headingLevel'>> &
147151
Omit<MarkdownOptions, 'headingLevel'> &
148152
Pick<MarkdownOptions, 'emoji'>): string => {
149-
const {name, documentation} = entry;
153+
const {name, documentation, jsDocs, url} = entry;
150154

151155
const markdown: string[] = [
152156
`${headingLevel}# ${emoji === undefined || emoji === null ? '' : ':gear: '}${name}\n`
@@ -156,6 +160,14 @@ const interfacesToMarkdown = ({
156160
markdown.push(`${documentation}\n`);
157161
}
158162

163+
const metadata = metadataToMarkdown({
164+
...jsDocsMetadata(jsDocs),
165+
url,
166+
emoji
167+
});
168+
169+
markdown.push(...metadata);
170+
159171
markdown.push(`| Property | Type | Description |`);
160172
markdown.push('| ---------- | ---------- | ---------- |');
161173

src/lib/parser/render.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const emojiTitle = ({
1010
} & Pick<MarkdownOptions, 'emoji'>): string =>
1111
emoji === undefined || emoji === null ? '' : ` :${emoji[key]}:`;
1212

13-
export const sourceCodeLink = ({
13+
const sourceCodeLink = ({
1414
url,
1515
emoji
1616
}: Pick<MarkdownOptions, 'emoji'> & Required<Pick<DocEntry, 'url'>>): string =>

src/test/mock.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,19 @@
426426
"kind": "text"
427427
}
428428
]
429+
},
430+
{
431+
"name": "see",
432+
"text": [
433+
{
434+
"text": "https",
435+
"kind": "text"
436+
},
437+
{
438+
"text": "://github.com/peterpeterparker/tsdoc-markdown",
439+
"kind": "text"
440+
}
441+
]
429442
}
430443
],
431444
"doc_type": "interface",

src/test/mock.md

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ function submit() {
9595
| ---------- | ---------- |
9696
| `MyObject.someFunction` | `() => void` |
9797

98-
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L282)
98+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L283)
9999

100100

101101
## :wrench: Constants
@@ -133,7 +133,7 @@ console.log(result.success); // true or false
133133
```
134134

135135

136-
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L299)
136+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L300)
137137

138138
### :gear: SOMETHING
139139

@@ -151,7 +151,7 @@ References:
151151
* [Source code](https://github.com/peterpeterparker/tsdoc-markdown)
152152

153153

154-
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L339)
154+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L340)
155155

156156

157157
## :factory: LedgerCanister
@@ -288,7 +288,12 @@ Description
288288

289289
Should differentiate methods / properties and static methods / properties
290290

291-
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L317)
291+
References:
292+
293+
* [https://github.com/peterpeterparker/tsdoc-markdown](https://github.com/peterpeterparker/tsdoc-markdown)
294+
295+
296+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L318)
292297

293298
### Static Methods
294299

@@ -300,7 +305,7 @@ Should differentiate methods / properties and static methods / properties
300305
| ---------- | ---------- |
301306
| `add` | `(n1: Number, n2: Number) => Number` |
302307

303-
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L327)
308+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L328)
304309

305310
### Methods
306311

@@ -312,7 +317,7 @@ Should differentiate methods / properties and static methods / properties
312317
| ---------- | ---------- |
313318
| `add` | `(n: Number) => Number` |
314319

315-
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L323)
320+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L324)
316321

317322
### Static Properties
318323

@@ -324,7 +329,7 @@ Should differentiate methods / properties and static methods / properties
324329
| ---------- | ---------- |
325330
| `world` | `string` |
326331

327-
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L319)
332+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L320)
328333

329334
### Properties
330335

@@ -336,7 +341,7 @@ Should differentiate methods / properties and static methods / properties
336341
| ---------- | ---------- |
337342
| `hello` | `string` |
338343

339-
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L318)
344+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L319)
340345

341346
## :nut_and_bolt: Enum
342347

@@ -347,6 +352,8 @@ Should differentiate methods / properties and static methods / properties
347352

348353

349354

355+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L183)
356+
350357
| Property | Type | Description |
351358
| ---------- | ---------- | ---------- |
352359
| `SECOND` | `1000` | |
@@ -357,6 +364,8 @@ Should differentiate methods / properties and static methods / properties
357364

358365

359366

367+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L188)
368+
360369
| Property | Type | Description |
361370
| ---------- | ---------- | ---------- |
362371
| `T1` | `` | |
@@ -373,6 +382,8 @@ Should differentiate methods / properties and static methods / properties
373382

374383
A Foo interface description.
375384

385+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L157)
386+
376387
| Property | Type | Description |
377388
| ---------- | ---------- | ---------- |
378389
| `hello` | `string` | Says hello. |
@@ -384,6 +395,13 @@ A Foo interface description.
384395

385396
Use a URL redirect to prevent broken links if you've moved a page or to shorten URLs.
386397

398+
References:
399+
400+
* [https://github.com/peterpeterparker/tsdoc-markdown](https://github.com/peterpeterparker/tsdoc-markdown)
401+
402+
403+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L259)
404+
387405
| Property | Type | Description |
388406
| ---------- | ---------- | ---------- |
389407
| `source` | `string` | The glob pattern or specific path to match for incoming requests that should be redirected. type: {StorageConfigSourceGlob} |
@@ -432,5 +450,5 @@ A type yolo
432450
| ---------- | ---------- |
433451
| `SatelliteConfig` | `Either<SatelliteId, SatelliteIds> and CliConfig and SatelliteConfigOptions` |
434452

435-
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L278)
453+
[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L279)
436454

src/test/mock.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,7 @@ export type StorageConfigSourceGlob = string;
254254
/**
255255
* Use a URL redirect to prevent broken links if you've moved a page or to shorten URLs.
256256
* @interface StorageConfigRedirect
257+
* @see https://github.com/peterpeterparker/tsdoc-markdown
257258
*/
258259
export interface StorageConfigRedirect {
259260
/**

0 commit comments

Comments
 (0)