From e713e28dee90f033fb0f9e0a602def3253749b27 Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Fri, 16 Feb 2024 09:05:13 +0100 Subject: [PATCH 1/3] feat: jsDocs support for Interfaces --- src/lib/markdown.ts | 13 +++++++++---- src/test/mock.json | 6 ++++++ src/test/mock.md | 5 +++-- src/test/mock.ts | 7 +++++++ 4 files changed, 25 insertions(+), 6 deletions(-) diff --git a/src/lib/markdown.ts b/src/lib/markdown.ts index b77b92d..c03ec48 100644 --- a/src/lib/markdown.ts +++ b/src/lib/markdown.ts @@ -104,11 +104,16 @@ const interfacesToMarkdown = ({ markdown.push(`| Property | Type | Description |`); markdown.push('| ---------- | ---------- | ---------- |'); - (entry.properties ?? []).forEach(({name, type, documentation}) => + (entry.properties ?? []).forEach(({name, type, documentation, jsDocs}) => { + const docs = (jsDocs ?? []).map( + ({name, text}: JSDocTagInfo) => + `${name}${text !== undefined ? `: ${text.map(({text}) => text).join('')}` : ''}` + ); + markdown.push( - `| \`${name}\` | \`${parseType(type ?? '')}\` | ${documentation !== undefined && documentation !== '' ? `${parseType(documentation).replace(/\r?\n|\r/g, '')}` : ''} |` - ) - ); + `| \`${name}\` | \`${parseType(type ?? '')}\` | ${documentation !== undefined && documentation !== '' ? `${parseType(documentation).replace(/\r?\n|\r/g, '')}` : ''}${docs.length > 0 ? ` ${docs.join('')}` : ''} |` + ); + }); markdown.push('\n'); diff --git a/src/test/mock.json b/src/test/mock.json index 5e4253e..bfa5393 100644 --- a/src/test/mock.json +++ b/src/test/mock.json @@ -191,6 +191,12 @@ "doc_type": "interface", "properties": [ {"name": "hello", "documentation": "Says hello.", "type": "string", "jsDocs": []}, + { + "name": "world", + "documentation": "Something", + "type": "string", + "jsDocs": [{"name": "default", "text": [{"text": "`hello`", "kind": "text"}]}] + }, {"name": "abc", "documentation": "", "type": "Abc", "jsDocs": []} ], "fileName": "src/test/mock.ts" diff --git a/src/test/mock.md b/src/test/mock.md index 7a8cc37..2680a3e 100644 --- a/src/test/mock.md +++ b/src/test/mock.md @@ -164,6 +164,7 @@ A Foo interface description. | Property | Type | Description | | ---------- | ---------- | ---------- | | `hello` | `string` | Says hello. | +| `world` | `string` | Something default: `hello` | | `abc` | `Abc` | | @@ -180,7 +181,7 @@ A type yolo | ---------- | ---------- | | `yolo` | `'string'` | -[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L136) +[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L143) ### :gear: Abc @@ -190,5 +191,5 @@ A type yolo | ---------- | ---------- | | `Abc` | `Foo and {hello: string}` | -[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L141) +[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/test/mock.ts#L148) diff --git a/src/test/mock.ts b/src/test/mock.ts index 1e2f8db..23e0ddd 100644 --- a/src/test/mock.ts +++ b/src/test/mock.ts @@ -127,6 +127,13 @@ export interface Foo { */ hello: string; + /** + * Something + * + * @default `hello` + */ + world?: string; + abc: Abc; } From 268bd2644883976c6b810222b07d9814a9aa9078 Mon Sep 17 00:00:00 2001 From: github-actions <41898282+github-actions[bot]@users.noreply.github.com> Date: Fri, 16 Feb 2024 08:05:37 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=A4=96=20Documentation=20auto-update?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d210af9..d00093f 100644 --- a/README.md +++ b/README.md @@ -162,7 +162,7 @@ Parameters: - `params.entries`: The entries of the documentation (functions, constants and classes). - `params.options`: Optional configuration to render the Markdown content. See `types.ts` for details. -[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/lib/markdown.ts#L245) +[:link: Source](https://github.com/peterpeterparker/tsdoc-markdown/tree/main/src/lib/markdown.ts#L250) ### :gear: generateDocumentation From 4ffb19adb9f27b99fa7d635e82e71fe99081700a Mon Sep 17 00:00:00 2001 From: David Dal Busco Date: Fri, 16 Feb 2024 11:29:15 +0100 Subject: [PATCH 3/3] refactor: rename field --- src/lib/markdown.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/lib/markdown.ts b/src/lib/markdown.ts index c03ec48..cc23c6b 100644 --- a/src/lib/markdown.ts +++ b/src/lib/markdown.ts @@ -105,13 +105,13 @@ const interfacesToMarkdown = ({ markdown.push('| ---------- | ---------- | ---------- |'); (entry.properties ?? []).forEach(({name, type, documentation, jsDocs}) => { - const docs = (jsDocs ?? []).map( + const jsDocsDescription = (jsDocs ?? []).map( ({name, text}: JSDocTagInfo) => `${name}${text !== undefined ? `: ${text.map(({text}) => text).join('')}` : ''}` ); markdown.push( - `| \`${name}\` | \`${parseType(type ?? '')}\` | ${documentation !== undefined && documentation !== '' ? `${parseType(documentation).replace(/\r?\n|\r/g, '')}` : ''}${docs.length > 0 ? ` ${docs.join('')}` : ''} |` + `| \`${name}\` | \`${parseType(type ?? '')}\` | ${documentation !== undefined && documentation !== '' ? `${parseType(documentation).replace(/\r?\n|\r/g, '')}` : ''}${jsDocsDescription.length > 0 ? ` ${jsDocsDescription.join('')}` : ''} |` ); });